C#编辑EXE使用的appSettings节点的Config文件
程序员文章站
2022-07-06 10:18:45
/// /// 保存配置文件的设定 /// /// /// public static void SaveAppConfig(string Key,string Value) { string strFilePath = System.Windows.Forms... ......
/// <summary>
/// 保存配置文件的设定
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
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");
}