Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software


ConfigurationSettings.GetConfig(sectionName.) method reads the contents of the sectionName from the web.config file in ASP.NET.

Is there a way, we can read contents from a different xml file, other than the web.config file?

Thanks much.

Tuesday, November 30, 2004

You're talking about parsing an XML file?

I'd read it, using either the XmlTextReader if you plan on going through the entire XML file, or XmlDocument if you are going for a specific node (and you'd use XPath to navigate directly to the node).

Thursday, December 02, 2004

I think the original poster meant is there a way to use ConfigurationSettings.GetConfig() with an XML file other than web.config.

The answer is no; the configuration file (the file that ConfigurationSettings reads from) for an AppDomain can only be specified when an AppDomain is created.  If you are creating the AppDomains yourself,  with AppDomain.CreateDomain(), you can use AppDomainSetup.ConfigurationFile to taregt a different XML file.  But just using basic ASP.NET, you are stuck with web.config.

John Lewicki
Monday, December 06, 2004

Actually this can be done. See Wrox ASP.NET Website Programming code for an example:,descCd-download_code.html

Basically you put the file name in Web.Config and then build a couple classes to handle get/set/cache for your config file.

HOWEVER, I ran into (?solveable?) problems accessing the configuration on background processes when using this approach. It took about 15 minutes to convert back to a custom configuration section inside web.config.

Sean Stapleton
Wednesday, January 12, 2005

It occurs to me I should have been clearer. What the approach shown in the book (and code download) shows is the creation of a custom configuration handler. The functionality mimics Configuration.GetConfig(), but actually uses your own classes.

In the code download, you would be looking for InstanceConfig.cs and InstanceSettings.cs in module "core".

Sean Stapleton
Wednesday, January 12, 2005

*  Recent Topics

*  Fog Creek Home