开发者

How to parse web.config file in c#

开发者 https://www.devze.com 2023-01-10 18:14 出处:网络
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

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 o开发者_StackOverflow中文版rder 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 ?


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消