Parsing web.config

  • Thread starter Thread starter Andrew Chalk
  • Start date Start date
A

Andrew Chalk

I am parsing my ASP.NET 2.0 web apps. web.config file. The following line
produces xnl with 0 elements

XmlNodeList xnl = xd.SelectNodes("/configuration/appSettings/add");

if web. config has:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="ErrorLogDirectory"
value="D:\WORK\Logger\CallView\20070508\bin" />
</appSettings>
....
However, it produces xnl with 1 element (the correct number) if I modify
web.config as follows:

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ErrorLogDirectory"
value="D:\WORK\Logger\CallView\20070508\bin" />
</appSettings>
....
I.e. xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" is deleted.

How can I get XmlNodeList to return the correct number of elements with the
former web.config syntax?

Many thanks.
 
Why do you need to parse your config file?

If you need to read your app config settings, just use this syntax:

string strErrLogDirectory =
System.Configuration.ConfigurationManager.AppSettings["ErrLogDirectory"];

Or, if you need the number of settings, use this:

int nNumberOfAppSettings =
System.Configuration.ConfigurationManager.AppSettings.Count;
 
Back
Top