1 ///
2 /// 修改AppSettings中配置
3 ///
4 /// key值
5 /// 相应值
6 public static bool SetConfigValue(string key, string value)
7 {
8 try
9 {
10 Configuration cOnfig= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
11 if (config.AppSettings.Settings[key] != null)
12 config.AppSettings.Settings[key].Value = value;
13 else
14 config.AppSettings.Settings.Add(key, value);
15 config.Save(ConfigurationSaveMode.Modified);
16 ConfigurationManager.RefreshSection("appSettings");
17 return true;
18 }
19 catch
20 {
21 return false;
22 }
23 }