C#
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,648 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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# ?
<configSections>
<section name="TestSIS" type="System.Configuration.NameValueSectionHandler"/>
<section name="MatchMMDS" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<TestSIS>
<add key="Daily" value="Test1D,Test2D,Test3D"/>
<add key="Weekly" value="Test06W,Test07W"/>
</TestSIS>
<MatchMMDS>
<add key="Daily" value="Match01D,Match02D"/>
<add key="Weekly" value="MatchI06W,MatchI07W,MatchI08W"/>
<add key="Monthly" value="Match06M,Match07W,Match08W,Match09W"/>
</MatchMMDS>
@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");
}
else
{
foreach (var key in applicationSettings.AllKeys)
{
Console.WriteLine(key + " = " + applicationSettings[key]);
}
}