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
  • 95,331
  • 80
  • 293
  • 426
Darqer
  • 2,770
  • 7
  • 43
  • 60
  • 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
  • 48,156
  • 8
  • 98
  • 113
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
  • 60,842
  • 17
  • 153
  • 183
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
  • 16,523
  • 18
  • 63
  • 108