1

I have C# windows application with XML file. After installing the set up file I need to edit the XML file time to time. But my XML file not going to the path where the executable is located. So that is giving error. With in a program I'm getting XML path like this.

private string PATH = Path.Combine(Application.StartupPath, "XMLFile1.xml");

Please some one can suggest a way to do.

slugster
  • 49,403
  • 14
  • 95
  • 145
Tom
  • 1,343
  • 1
  • 18
  • 37
  • @Ghost Answer that was a bad edit suggestion which should not have been approved - you simply added backticks where they weren't necessary and didn't fix other problems in the text. Please pay more attention next time. – slugster Mar 11 '14 at 05:15
  • Better to save the XML file in some common location – Sumeshk Mar 11 '14 at 05:16
  • Why don't you place the xml file into same directory where executable resides ? you can simply add the xml file to the setup and copy to the same location – Kurubaran Mar 11 '14 at 05:19

4 Answers4

0

You have to include it in project. Here's a helpful link: How to include XML file while creating setup file for windows application

slugster
  • 49,403
  • 14
  • 95
  • 145
Rahul
  • 37
  • 1
  • 8
  • Just a pointer: you should format your link nicely, i.e. use the title of the page you are linking to and format that title as the link. – slugster Mar 11 '14 at 05:17
0

If you have installed your application on Windows Vista, 7, or 8, it's quite possible that you get security exceptions. Since you haven't told what kind of errors you get I have to ask my crystal ball to think with me.

He thinks that because you are trying to write in a protected folder you get an exception.

He suggest you move the XML to %appdata% or %localappdata%

Anemoia
  • 7,928
  • 7
  • 46
  • 71
  • I'm getting this error when opening the program through exe. System.IO.FileNotFoundException: Could not find file 'C:\Users\Thameera\AppData\Local\Apps\2.0\RBCOECTY.PHY\GPGXMYG8.WOK\fish..tion_811dfca5da066d3a_0001.0000_5e3e1ef3b3b42246\XMLFile1.xml'. File name: 'C:\Users\Thameera\AppData\Local\Apps\2.0\RBCOECTY.PHY\GPGXMYG8.WOK\fish..tion_811dfca5da066d3a_0001.0000_5e3e1ef3b3b42246\XMLFile1.xml' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) – Tom Mar 11 '14 at 05:25
0

Use Application.ExecutablePath, the Application.StartupPath property will change if your app is started from desktop shortcut or any other shortcuts.

private string PATH = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "XMLFile1.xml");
Salar
  • 2,088
  • 21
  • 26
0

while your application starts copy your XML file to a common folder path, if it is not exist in the path. Do your edit on the xml file in the common folder.

better to use common folder as Local application Data Folder

Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Your application name") 
Sumeshk
  • 1,980
  • 20
  • 33