
Asp.net中自定义config文件的使用方法。
XML
1 2 3 4 5
|
<?xml version="1.0" encoding="utf-8"?> <color> <add key="1" color="red"></add> <add key="2" color="blue"></add> </color>
|
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public Dictionary<int, string> ItemColor = GetUrl(); protected static Dictionary<int, string> () { Dictionary<int, string> color = new Dictionary<int, string>(); XmlTextReader reader = new XmlTextReader(System.Web.HttpContext.Current.Server.MapPath("color.config")); XmlDocument doc = new XmlDocument(); doc.Load(reader); var count = doc.DocumentElement.ChildNodes.Count; foreach (XmlNode node in doc.DocumentElement.ChildNodes) { color.Add(Convert.ToInt32(node.Attributes["key"].Value), node.Attributes["color"].Value); } return color; }
|
近期评论