How to update an value in app.config file?

后端 未结 2 1905
暗喜
暗喜 2020-12-18 15:42

This is my code:

Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection settin         


        
相关标签:
2条回答
  • 2020-12-18 16:13

    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");
    
    0 讨论(0)
  • 2020-12-18 16:32

    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 讨论(0)
提交回复
热议问题