Read contents of app config

Padmanabhan, Venkatesh 120 Reputation points

Hi. I have a web.config file which contains the below . How to read the Key and value of each of the sections - TestSIS and MatchMMDS using c# ?

		<section name="TestSIS" type="System.Configuration.NameValueSectionHandler"/>
		<section name="MatchMMDS" type="System.Configuration.NameValueSectionHandler"/>

		<add key="Daily" value="Test1D,Test2D,Test3D"/>
		<add key="Weekly" value="Test06W,Test07W"/>		
		<add key="Daily" value="Match01D,Match02D"/>
		<add key="Weekly" value="MatchI06W,MatchI07W,MatchI08W"/>
		<add key="Monthly" value="Match06M,Match07W,Match08W,Match09W"/>
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,366 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sudipta Chakraborty - MSFT 1,101 Reputation points Microsoft Employee

    @Padmanabhan, Venkatesh You will need to add System.Configuration assembly reference to access configuration settings, using ConfigurationManager. To add the reference, just right click References and click to add references. In C# application you can use the following code:

    var applicationSettings = ConfigurationManager.GetSection("TestSIS") as NameValueCollection; // for reading MatchMMDS replace TestSIS to MatchMMDS
        if (applicationSettings.Count == 0)
            Console.WriteLine("Application Settings are not defined");
            foreach (var key in applicationSettings.AllKeys)
                Console.WriteLine(key + " = " + applicationSettings[key]);
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful