zoukankan      html  css  js  c++  java
  • C# 修改配置文件

    /// <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");
    }

  • 相关阅读:
    条件
    循环
    列表
    字典
    集合
    公共操作
    函数-2
    函数-1
    函数加强
    文件操作
  • 原文地址:https://www.cnblogs.com/derekhan/p/10810542.html
Copyright © 2011-2022 走看看