So I understand it is a best practice to save the application configuration files under the
AppData folder, rather than in Program Files, since UAC will restrict write acces to the
Program Files folder, which is fine.
Now, saving the configuration file to another location is no problem, using the
However, when I load the application, I expect some settings to be read. From what I know, this is done either using direct calls to the ConfigurationManager class, either initializing a Configuration object. For the first case, a example is this:
if (ConfigurationManager.AppSettings["Title"] != null)
this.Title = ConfigurationManager.AppSettings["Title"];
titleTextBox.Text = ConfigurationManager.AppSettings["Title"];
For the second case, I would use it like this:
Configuration config =
string setting = config.AppSettings.Settings["Title"].Value.ToString();
So, if the application runs in the Program Files folder, an exception is thrown when I save the file. However, if I save the file using SaveAs and save it to AppData folder, obviously, when loading, the settings are not loaded from the AppData folder,
but from the configuration file existing in the Program Files folder.
One way to solve
View Complete Post