本文介绍了更改的AppConfig上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更新运行时用下面的代码了AppConfig文件。我没有得到一个错误,但它并没有更新我的配置文件。
System.Configuration.Configuration配置=
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
字符串的属性oldValue = config.AppSettings.Settings [用户名]值。
config.AppSettings.Settings [用户名] =价值的NewValue。
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(的appSettings);
解决方案
添加 config.AppSettings .SectionInformation.ForceSave = TRUE;
会做的伎俩。那么你应该看看在 YourProject.vshost.exe.config
调试时,贾斯汀说。修改的内容在那里。
I am trying to update the appconfig file on run time with the following code. I do not get an error but it does not update my config file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string oldValue = config.AppSettings.Settings["Username"].Value;
config.AppSettings.Settings["Username"].Value = "NewValue";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
解决方案
Adding the config.AppSettings.SectionInformation.ForceSave = true;
will do the trick. You should then look in YourProject.vshost.exe.config
when debugging as Justin said. The modifications are saved there.
这篇关于更改的AppConfig上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!