zoukankan      html  css  js  c++  java
  • appSetting 在单独文件的读写

        #region appSetting
    
        /// <summary>
        /// 设定 appSetting
        /// </summary>
        /// <param name="AppKey"></param>
        /// <param name="AppValue"></param>
        public static void SetValue(string AppKey, string AppValue)
        {
            XmlDocument xDoc = new XmlDocument();
            string path = HttpContext.Current.Server.MapPath("~/");
            xDoc.Load(path + "Config.xml");
            XmlNode xNode;
            XmlElement xElem1;
            XmlElement xElem2;
            xNode = xDoc.SelectSingleNode("//appSettings");
            xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
            if (xElem1 != null)
            {
                xElem1.SetAttribute("value", AppValue);           
            }
            else
            {
                xElem2 = xDoc.CreateElement("add");
                xElem2.SetAttribute("key", AppKey);
                xElem2.SetAttribute("value", AppValue);
                xNode.AppendChild(xElem2);
            }
            xDoc.Save(path + "Config.xml");
        }
    
        /// <summary>
        /// appSetting 根据Key取Value值 没有返回空字符
        /// </summary>
        /// <param name="key"></param>
        public static string GetValue(string key)
        {
            object appValue = ConfigurationManager.AppSettings[key];
            return null != appValue ? appValue.ToString().Trim() : "";
        }
    
        #endregion
    
    
    
  • 相关阅读:
    SQL Server没有足够的内存继续执行程序 (mscorlib)的解决办法
    在IIS上搭建WebSocket服务器(一)
    端口号被占用
    2018年 年度总结
    一个人颓废的九大根源
    Arrays.asList() 踩坑
    电脑关机命令
    div 悬浮
    ajax中 踩过的坑
    oracle 密码过期问题
  • 原文地址:https://www.cnblogs.com/chenmfly/p/6170531.html
Copyright © 2011-2022 走看看