RubenHerman
RubenHerman

Reputation: 1854

reloading app.config after writing

When I use this to write to my app.config file:

Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Wachtwoord"].Value = "Test";
config.Save();
ConfigurationManager.RefreshSection("appSettings");

I can read it again. But when i close and restart the program, the value of "Wachtwoord" has changed again to the old value.

Does anybody how I could fix this?

Thanks

Upvotes: 2

Views: 708

Answers (1)

Tim Lloyd
Tim Lloyd

Reputation: 38484

Are you sure that this has not been caused by Visual Studio overwriting your settings file when you build the project? The original settings file lives with your source code, whereas you run the application from your build output directory (e.g. bin\debug). You may be making changes to the copy in the build output directory when you run the application, which will make changes to the version there. When you rebuild the project, the settings file will be overwritten.

Upvotes: 3

Related Questions