[英]How to Modify AppSettings key value at run time?
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["SourceFilePath"].Value = SourcePathTextBox.Text.ToString();
config.AppSettings.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appSettings");
这是我更改键设置值的代码。 它正在正常工作,但没有错误,但值在app.config文件中的应用程序设置中未更改。请帮助我。
您提供的代码不会持久保存对配置文件的更改,而只是在内存中进行更改。 您可以使用断点检查更改,也可以使用以下代码显示更新的值:。
lblConfigChanges.Text=System.Configuration.ConfigurationManager.AppSettings["SourceFilePath"].ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.