1

I am trying to retrieve some information from a .config file. I need to search for specific tags and get the attributes in those tags. For example in application tag i need to get the attribute path. I don't need any other information from the .config file. I was just going through XmlTextReader but then realised i need a config file and don't know if it is the right way.

slugster
  • 49,403
  • 14
  • 95
  • 145
Aadi Droid
  • 1,689
  • 4
  • 22
  • 46
  • Is it a .net Config file? Could you please provide an example? – WaltiD Jun 29 '11 at 07:10
  • 3
    Are you looking for [`ConfigurationManager`](http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx) – V4Vendetta Jun 29 '11 at 07:11
  • Guys it is a .config file. Ok here is the file i need to read .. %windir%\system32\inetsrv\config\applicationHost.config i need to pull out only data withing the and – Aadi Droid Jun 29 '11 at 07:15
  • I am using this code now to get the content within the sites tag, how do i filter down to get info of the site tag that lies withing sites tag ? XmlTextReader xtr = new XmlTextReader(@"\\rabaro-dtp2\C$\Windows\system32\inetsrv\config\applicationHost.config"); while (xtr.Read()) { // Do some work here on the data. if (xtr.Name.Equals("sites")) { } } Console.ReadLine(); – Aadi Droid Jun 29 '11 at 08:58

2 Answers2

2

The right way is using a ConfigurationElement descendant. For each section in app.config / web.config you have a specific class to manage that section. If you need to modify the app.config / web.config file, you can use the ConfigurationManager class.

mnieto
  • 3,744
  • 4
  • 21
  • 37
1

I found Using the File attribute of the appSettings element of a .NET config file

And you must read this great article about using configuration file in .NET

Also found Read config file using XMl reader

Community
  • 1
  • 1
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364