I want to save new values to settings in Windows Forms. I looked up the other posts on this topic, and tried using code from the answers there, but to no avail.
Here's my code:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["DatabasePassword"].Value = textBoxPassword.Text;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
According to this post, and various others, this code should change the values in the exe.config file at the very least. But App.config, .exe.config, and .vhost.exe.config are all unchanged. Why is this not working?
I should also mention that this code is inside a buttonClick event.
Update: I've managed to get a change in .vhost.exe.config by using a .Remove(key) and .Add(key, value) , though this does inconveniently rearrange the document so that the new key is at the bottom, and on top of that, the .vhost.exe settings appear to have no effect. The only configuration that the program seems to draw data from is App.Config. I assume I'll need some special code to specifically read from the .vhost.exe.config instead?