周口12345 ZhouKou12345_API 官网山谷开发,工单接口对接(有文档)

Configs.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Configuration;
  2. using System.Web;
  3. namespace CallCenter.Utility
  4. {
  5. public class Configs
  6. {
  7. //public static System.Xml.XmlDocument xDoc;
  8. //public static System.Xml.XmlNode xNode;
  9. //static Configs()
  10. //{
  11. // xDoc = new System.Xml.XmlDocument();
  12. // xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
  13. // xNode = xDoc.SelectSingleNode("//appSettings");
  14. //}
  15. /// <summary>
  16. /// 根据Key取Value值
  17. /// </summary>
  18. /// <param name="key"></param>
  19. public static string GetValue(string key)
  20. {
  21. System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
  22. xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
  23. System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
  24. var xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
  25. return xElem1?.GetAttribute("value") ?? "";
  26. }
  27. /// <summary>
  28. /// 根据Key修改Value
  29. /// </summary>
  30. /// <param name="key">要修改的Key</param>
  31. /// <param name="value">要修改为的值</param>
  32. public static void SetValue(string key, string value)
  33. {
  34. System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
  35. xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
  36. System.Xml.XmlNode xNode = xDoc.SelectSingleNode("//appSettings");
  37. //System.Xml.XmlNode xNode;
  38. System.Xml.XmlElement xElem1;
  39. System.Xml.XmlElement xElem2;
  40. xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
  41. if (xElem1 != null) xElem1.SetAttribute("value", value);
  42. else
  43. {
  44. xElem2 = xDoc.CreateElement("add");
  45. xElem2.SetAttribute("key", key);
  46. xElem2.SetAttribute("value", value);
  47. xNode.AppendChild(xElem2);
  48. }
  49. xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
  50. }
  51. }
  52. }