Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to read XML files without writing full path, so my code would work when copied to other computers. With visual studio I added 2 XML files to project (Windows Application) and don't know best way to read those files. Hope I described my problem clearly. Maybe I needed to add those txt files differentely (like directly to same folder as .exe file)?


What I have tried:

1.
C#
XElement element = XElement.Load("WH_Num.xml");

2.
C#
XElement element = XElement.Load(@" C:\Users\nandang\Desktop\GUI_SETUP\JUNE_15_SetUp\3\Application Files\WH_Num.xml");


That Both 2 code are working for my PC, But when i publish and install setup file in other computer i wont work.

please any one suggest me best way to give a XML path and that path could be work for all other computer.
Posted
Updated 15-Jun-20 20:36pm
Comments
Maciej Los 16-Jun-20 3:54am    
Are you sure that setup program has been installed WH_num.xml file on client machine?

1 solution

If you load a file name without any path information, it will only be found if it is located in the current directory - normally the same folder as the EXE file, but its doesn't have to be as several things can change it, including a shortcut to the EXE file in Windows which allows the user to specify the "Start in" folder.
And in production, storing data which changes in the same folder as the EXE file is a no-no as it's generally write protected for virus security.

What you need to do is store data in a "generic" folder that is available (but different) on every PC. Have a look here: Where should I store my data?[^] - it gives code for locating data under user folders.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900