XML file not written in intended directory
-
First off, please forgive me if this is in the wrong section. I'm not sure if the probelm is my VB.Net code or my understanding of installers. I've written a Windows Forms Application which stores it's preference settings in an XML file. I'm having problems with the file not being written to the directory I intend. I want to write the XML file in the application folder
C:\Program Files\MyApplication
, but when I install and then run my application it writes the XML file inC:\Users\MyAccount\AppData\Local\VirtualStore\Program Files\MyApplication
(This folder does not contain a copy of the executable, and is empty apart from the files written by my application when it runs). I've made the following declarations in the application for the file name and path:Private strApplicationPath As String = Application.StartupPath
Private strPreferencesFileName As String = "\Preferences.ini"I have my application preferences stored in a DataSet called
dsPreferences
, and use the following code to write the file:dsPreferences.WriteXml(strApplicationPath & strPreferencesFileName, XmlWriteMode.WriteSchema)
To help me sort out what's going on I've also added a lable to the form called
lblPath
to display the file name and path:lblPath.Text = strApplicationPath & strPreferencesFileName
When I do a Release Build, and run the executable everything seems to work fine. The XML file is written in the same directory as the executable ie
C:\Projects\MyApplication\bin\Release
andlblPath.Text
also displaysC:\Projects\MyApplication\bin\Release
HOWEVER! I then use "Inno Setup 5" and "ISTool" to create an installer, and then install the application toC:\Program Files\MyApplication
. Now when I run the application the XML file is written toC:\Users\MyAccount\AppData\Local\VirtualStore\Program Files\MyApplication
instead ofC:\Program Files\MyApplication
where the executable is, even thoughlblPath.Text
still shows thatstrApplicationPath & strPreferencesFileName
=C:\Program Files\MyApplication
!?! :confused: The same issue is happening with the SqlCe database file for the application. - What is this VirtualStore? - Why is the XML file written there when I've been reasonably explicit that it should be stored in the same folder as the executable? - How can I make sure the file gets written to th -
First off, please forgive me if this is in the wrong section. I'm not sure if the probelm is my VB.Net code or my understanding of installers. I've written a Windows Forms Application which stores it's preference settings in an XML file. I'm having problems with the file not being written to the directory I intend. I want to write the XML file in the application folder
C:\Program Files\MyApplication
, but when I install and then run my application it writes the XML file inC:\Users\MyAccount\AppData\Local\VirtualStore\Program Files\MyApplication
(This folder does not contain a copy of the executable, and is empty apart from the files written by my application when it runs). I've made the following declarations in the application for the file name and path:Private strApplicationPath As String = Application.StartupPath
Private strPreferencesFileName As String = "\Preferences.ini"I have my application preferences stored in a DataSet called
dsPreferences
, and use the following code to write the file:dsPreferences.WriteXml(strApplicationPath & strPreferencesFileName, XmlWriteMode.WriteSchema)
To help me sort out what's going on I've also added a lable to the form called
lblPath
to display the file name and path:lblPath.Text = strApplicationPath & strPreferencesFileName
When I do a Release Build, and run the executable everything seems to work fine. The XML file is written in the same directory as the executable ie
C:\Projects\MyApplication\bin\Release
andlblPath.Text
also displaysC:\Projects\MyApplication\bin\Release
HOWEVER! I then use "Inno Setup 5" and "ISTool" to create an installer, and then install the application toC:\Program Files\MyApplication
. Now when I run the application the XML file is written toC:\Users\MyAccount\AppData\Local\VirtualStore\Program Files\MyApplication
instead ofC:\Program Files\MyApplication
where the executable is, even thoughlblPath.Text
still shows thatstrApplicationPath & strPreferencesFileName
=C:\Program Files\MyApplication
!?! :confused: The same issue is happening with the SqlCe database file for the application. - What is this VirtualStore? - Why is the XML file written there when I've been reasonably explicit that it should be stored in the same folder as the executable? - How can I make sure the file gets written to thlet me guess - you're running on Vista, right ? .. Im not a Vista pro, but I found this for example "An app that requires write access into program files sees c:\program files\MyApp\UserData, but it's really in c:\users\stephen\AppData\VirtualStore\Program Files\MyApp\UserData" Its a 'redirection'/security/UAC thing that Vista does Ive posted some links that [may] help http://social.msdn.microsoft.com/Forums/en-NZ/windowssecurity/thread/e85a62b7-d7c6-4d77-8b4c-11d5892b7218[^] http://www.itwriting.com/blog/141-peeking-into-vistas-virtual-store.html[^]
-
let me guess - you're running on Vista, right ? .. Im not a Vista pro, but I found this for example "An app that requires write access into program files sees c:\program files\MyApp\UserData, but it's really in c:\users\stephen\AppData\VirtualStore\Program Files\MyApp\UserData" Its a 'redirection'/security/UAC thing that Vista does Ive posted some links that [may] help http://social.msdn.microsoft.com/Forums/en-NZ/windowssecurity/thread/e85a62b7-d7c6-4d77-8b4c-11d5892b7218[^] http://www.itwriting.com/blog/141-peeking-into-vistas-virtual-store.html[^]
I think you hit the nail on the head there! Thanks! :thumbsup::thumbsup: