赞
踩
读:
- /// <summary>
- /// 获取配置文件AppSeting节点数据信息
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- public static string GetAppSettingKeyValue(string key)
- {
- Configuration cfg = ConfigurationManager.OpenExeConfiguration(@"WinDraw.dll");
- return cfg.AppSettings.Settings[key].Value;
- }
- /// <summary>
- /// 保存配置文件AppSeting节点的数据信息
- /// </summary>
- /// <param name="key"></param>
- /// <param name="value"></param>
- public static void SaveAppSettingKeyValue(string key, string value)
- {
- Configuration cfg = ConfigurationManager.OpenExeConfiguration(@"WinDraw.dll");
-
- bool isExist = false;
- foreach (string k in cfg.AppSettings.Settings.AllKeys)
- {
- if (k == key)//判断是否存在对应的节点
- {
- isExist = true;
- }
- }
-
- if (isExist)//如果存在则直接赋值
- {
- cfg.AppSettings.Settings[key].Value = value;
- }
- else//不存在就创建
- {
- cfg.AppSettings.Settings.Add(key, value);
- }
- cfg.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。