开发者

Updating a value in app.config at runtime

I've got开发者_StackOverflow two projects under the same solution. I use one project to update the app.config file of the second project. I manage to read the values I need, by using the GetSection method and the ClientSettingsSection class, but I can't find how to update those values.


ConfigurationManager.RefreshSection(sectionName);

Do you mean this?


You can do something like this:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("MyKey", "MyValue);
config.Save(ConfigurationSaveMode.Modified);

But the application configuration file is cached, so you need to call the ConfigurationManager.RefreshSection() method: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.refreshsection.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜