.net 如何修改config文件

by kevin 25. 十月 2018 11:31 >
string appConfigFile = Assembly.GetEntryAssembly().Location;
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(appConfigFile);
AppSettingsSection appSettings = (AppSettingsSection)appConfig.GetSection("appSettings");
var config = UploadConfig;
appSettings.Settings["KEY"].Value = "VALUE";
appConfig.Save();
ConfigurationManager.RefreshSection("appSettings");

留一份代码,只是为了以后使用ctrl+C、ctrl+V大法。

分享到: 更多