Adam Kłosowski
Adam Kłosowski

Reputation: 1

XML saved by application installed in Program Files: where is it?

I've spent the last two hours Googling on this with no results, so…

I am developing an application which uses XML files to save data. These files are supposed to exist in the same directory as the program executable. I use:

string filePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\xml\\filename.xml";

It works.

I've created the installation file in Inno Setup. This works as well, copying my XML files exactly where I want them to go.

I open my application directly from the installation folder, from the Start menu icon, from a desktop shortcut, and it works fine.

I make some changes to my program, then I close it and start it again. Everything is fine: all the saved changes are read back from the XML.

But then I open the specified XML file and there are no changes!

I wouldn't bother as at least it's working, but:

  1. When I uninstall the application then install it again to the same directory, changes made to the previously installed file are still there!
  2. I'm very curious to know what's happening.

This only happens if the program is installed to Program Files. If I install it to My Documents, changes are shown in the XML files and after reinstalling it the default settings are restored as expected.

My questions are:

  1. Where are those XML files being stored, and how can I load it if the specified path points to Program Files and they are not there?
  2. Obviously, how do I fix it?

EDIT Finally found those files in C:\Users[USERNAME]\AppData\Local\VirtualStore\Program Files[APPNAME]

Upvotes: 0

Views: 1655

Answers (2)

Arie
Arie

Reputation: 5373

Check what is saved into your local application data folder (it's \Users[USERNAME]\AppData\Local\ for Windows 7).

It looks as if your app didn't have rights to save things in your ProgramFiles folder and saved it where it could, probably in this location:

String appData = 
    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

Also you may try running your application as administrator and check if changes to your xml data still doesn't show.

Upvotes: 1

Cant you print out the value of

    System.IO.Path.GetDirectoryName(Application.ExecutablePath)

then you should be able to see where your xml files are stored, if it is a console application just use Console to print if it is WPF print it to a label or something

Upvotes: 0

Related Questions