2

I have web.config file from some application. It is located in some random location. I have to parse this web.config file (get all keys names and values). I tried to use ConfigurationManager class in order to get those data however, it throws exception when I try to get some Sections (Configuration->GetSection('section name')). It throws exception because I do not have dll that this section points to (because I have only web.config not whole application). It seems that GetSection method check underlying dll in order to get more info, but I just need value (name of dll).

What can I do, to turn off this mechanism, do you know other simple solutions to get it done ?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Darqer
  • 2,847
  • 9
  • 45
  • 65
  • have a look at this post. seems this is what your are looking for https://stackoverflow.com/questions/4738/using-configurationmanager-to-load-config-from-an-arbitrary-location – ajay_whiz Aug 10 '10 at 07:11

3 Answers3

7

You are just going to have to use XmlDocument or XDocument (3.5) to parse the file.

Strelok
  • 50,229
  • 9
  • 102
  • 115
2

If you just want to read the text, and not do any web.config-specific processing, use the fact that a .config file is XML, and use your favourite usual way of reading and parsing XML.

AakashM
  • 62,551
  • 17
  • 151
  • 186
2

Web.Config files are just XML and an be read using a number of .Net XML objects. Below are a couple of methods.

Tutorial on reading an XML file using XmlTextReader http://support.microsoft.com/kb/307548

Tutorial on reading an XML file using LinqToSQL http://www.mssqltips.com/tip.asp?tip=1524

Gavin
  • 17,053
  • 19
  • 64
  • 110