使用XMl阅读器读取配置文件 [英] Read config file using XMl reader
本文介绍了使用XMl阅读器读取配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
最好的方法是检索webconfig值是使用System.Configuration.ConfigurationManager.AppSettings;
要从xml reader读取webconfig的值:
private void loadConfig()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath(〜/)+web.config);
XmlNode xnodes = xdoc.SelectSingleNode(/ configuration / appSettings);
foreach(xmlNode xnn in xnodes .ChildNodes)
{
ListBox1.Items.Add(xnn.Attributes [0] .Value +=+ xnn.Attributes [1 ]。
}
}
参考: http://dotnetacademy.blogspot.com/2010/10/read- config-file-using-xml-reader.html
I have a bunch of key in AppSettings section of my web.config file. I want to read the key and values of those app settings using XML reader technique and populate them in the list box.
解决方案
The best way is to retrive webconfig values is to use System.Configuration.ConfigurationManager.AppSettings;
To retrive values of webconfig from xml reader:
private void loadConfig()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load( Server.MapPath("~/") + "web.config");
XmlNode xnodes = xdoc.SelectSingleNode ("/configuration/appSettings");
foreach (XmlNode xnn in xnodes .ChildNodes)
{
ListBox1.Items.Add(xnn.Attributes[0].Value + " = " + xnn.Attributes[1].Value );
}
}
Reference:http://dotnetacademy.blogspot.com/2010/10/read-config-file-using-xml-reader.html
这篇关于使用XMl阅读器读取配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文