Parsing web.config

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.
 
A

Ashot Geodakov

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top