在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Collections.Generic; using System.Text; using System.Configuration; using System.Xml; using System.Web; namespace MSCL { /// <summary> /// 配置文件帮助类 /// </summary> public class ConfigExtHelper { /* <?xml version="1.0" encoding="utf-8" ?> <config> <token>king</token> <cookie>123456</cookie> <pwd>123456</pwd> </config> */ /// <summary> /// xml文件路径 /// </summary> public static string filepath = System.Web.HttpContext.Current.Server.MapPath("/XML/config.xml"); /// <summary> /// 设置值 /// </summary> /// <param name="key">key</param> /// <param name="value">value</param> public static void Set(string key, string value) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filepath); XmlNode node; node = xmlDoc.SelectSingleNode("config/" + key); if (node == null) { XmlElement n = xmlDoc.CreateElement(key); n.InnerText = value; xmlDoc.SelectSingleNode("config").AppendChild(n); } else { node.InnerText = value; } xmlDoc.Save(filepath); } /// <summary> /// 根据key获取value /// </summary> /// <param name="key">key</param> /// <returns></returns> public static string Get(string key) { //获得数据 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filepath); XmlNode node; node = xmlDoc.SelectSingleNode("config/" + key); string str = node == null ? "" : node.InnerText; return str; } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论