C# 修改配置文件
2021-06-05 05:03
标签:lse 文件 ble odi tin for each sum void /// C# 修改配置文件 标签:lse 文件 ble odi tin for each sum void 原文地址:https://www.cnblogs.com/derekhan/p/10810542.html
/// 保存配置文件的设定
///
///
///
public static void SaveAppConfig(string Key, string Value)
{
string strFilePath = System.Windows.Forms.Application.ExecutablePath;
Configuration objConfig = ConfigurationManager.OpenExeConfiguration(strFilePath);
bool bolExist = false;
foreach (string Item in objConfig.AppSettings.Settings.AllKeys)
{
if (Item == Key)
{
bolExist = true;
break;
}
}
if (bolExist)
{
objConfig.AppSettings.Settings.Remove(Key);
}
objConfig.AppSettings.Settings.Add(Key, Value);
objConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}