VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之C#编辑EXE使用的appSettings节点的Config文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/// <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");
        }

相关教程