#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


相关文章:

  • 2021-11-29
  • 2021-07-02
  • 2022-12-23
  • 2021-05-30
  • 2022-01-29
  • 2021-08-23
  • 2021-11-29
  • 2021-05-31
猜你喜欢
  • 2021-06-05
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2021-10-06
  • 2022-01-10
  • 2021-09-14
相关资源
相似解决方案