Tuesday, October 5, 2010

Read config file using XML reader

The best way is to use System.Configuration.ConfigurationManager.AppSettings; to retrive values of webconfig but from xml reader you can also do that:


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 );
}

}

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates