use*_*747 2 c# xml web-config drop-down-menu
我在web.config文件的AppSettings部分有一堆密钥.我想使用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].Value );
}
}
Run Code Online (Sandbox Code Playgroud)
参考:http://dotnetacademy.blogspot.com/2010/10/read-config-file-using-xml-reader.html