/// <summary>
        /// 保存appSetting
        /// </summary>
        /// <param name="key">appSetting的KEY值</param>
        /// <param name="value">appSetting的Value值</param>
        private static void SetAppSetting(string key, string value)
        {
            // 创建配置文件对象
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (config.AppSettings.Settings[key] != null)
            {
                // 修改
                config.AppSettings.Settings[key].Value = value;
            }
            else
            {
                // 添加
                AppSettingsSection ass = (AppSettingsSection)config.GetSection("appSettings");
                ass.Settings.Add(key, value);
            }

            // 保存修改
            config.Save(ConfigurationSaveMode.Modified);

            // 强制重新载入配置文件的连接配置节
            ConfigurationManager.RefreshSection("appSettings");
        }

 

相关文章:

  • 2021-11-24
  • 2021-09-28
  • 2021-09-10
  • 2021-05-24
  • 2021-11-28
  • 2021-12-11
  • 2021-11-13
  • 2021-12-25
猜你喜欢
  • 2021-11-04
  • 2021-11-19
  • 2021-12-31
  • 2021-09-25
  • 2021-12-15
  • 2021-11-14
  • 2021-08-19
相关资源
相似解决方案