我的 web.config 文件的 AppSettings 部分有一堆 key 。我想使用 XML 阅读器技术读取这些应用程序设置的键和值,并将它们填充到列表框中。
最佳答案
检索 webconfig 值的最佳方法是使用 System.Configuration.ConfigurationManager.AppSettings;
从 xml 阅读器中检索 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].Value );
}
}
引用:http://dotnetacademy.blogspot.com/2010/10/read-config-file-using-xml-reader.html
关于c# - 使用 XMl 阅读器读取配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868179/