![](/img/trans.png)
[英]How to update app settings key value pair dynamically on app.config file in c# winforms
[英]How to update an value in app.config file?
這是我的代碼:
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection settings = configuration.AppSettings.Settings;
settings["IP"].Value = "10.0.0.2";
configuration.Save(ConfigurationSaveMode.Modified);
當我中斷settings["IP"].Value
行時,我得到正確的值。
該方法已完成,沒有任何錯誤,但是app.config文件保持不變。
此代碼應工作:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["IP"].Value = "10.0.0.2";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
據我所知, you can't persist the updated value in App.config
。 如果要保留配置值,請執行常規的XML操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.