开发者

How to update an value in app.config file?

This is my code:

Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection settings = configuration.AppSettings.Settings;  
settings["IP"].Value = "10.0.0.2";
configuration.Save(Configu开发者_开发知识库rationSaveMode.Modified);

when I break on settings["IP"].Value line, i get the correct value.

The method completes without any errors but app.config file remains unchanged.


This code should work:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

config.AppSettings.Settings["IP"].Value = "10.0.0.2";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");


As per my knowledge you can't persist the updated value in App.config. If you want to persist the config value,do the normal XML operation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜