learned/learning/to learn RSS 2.0
# Monday, 01 June 2009

You can add your own configuration sections in Web.config or App.config file. There might be some good way to do it, if so, please let me know.

 

Step 1

Add the follwing inside <configSections> tag:

<configSections>

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

</configSections>

 

Step 2

Add your custom section before or after <appSettings> but after <configSections>

<customSection>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection>

 

Your app.config will be like this

 ---------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>

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

  </configSections>

 

  <!--<Custom Seciton>-->

<customSection>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection>

 

 <appSettings>

    <add key="tesing" value="abc" />

 </appSettings>

 

  <system.web>

  </system.web>

</configuration>

  --------------------------------------------------------------------------------------------------------------

Step 3

How to access it?

 

NameValueCollection colCustomSection = (NameValueCollection)ConfigurationManager.GetSection("customSection");

string key, value;

 

for (int count = 0; count < colCustomSection.Count; count++)

{

   // we can get the keys

   key = colCustomSection.GetKey(count);

   // we can get the values

   value = colCustomSection.Get(count);

 

}

 

 

To add multiple sections

 

Add this inside <configSections>

<configSections>

<sectionGroup name ="customSectionGroup">

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

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

</sectionGroup>

</configSections>

 

Add this around your custom section:

<customSectionGroup>

<customSection1>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection1>

<customSection2>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection2>

</customSectionGroup>

 

To access it, just change the path:

NameValueCollection colCustomSection = (NameValueCollection)ConfigurationManager.GetSection("customSectionGroup/customSection1");

 

customSectionGroup/customSection1 or customSectionGroup/customSection2

 

Monday, 01 June 2009 18:43:34 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET
Comments are closed.
Navigation
Archive
<2017 August>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Gokulnath
Sign In
Statistics
Total Posts: 41
This Year: 0
This Month: 0
This Week: 0
Comments: 47
Themes
Pick a theme:
All Content © 2017, Gokulnath
DasBlog theme 'Business' created by Christoph De Baene (delarou)
The new movement has made a number of changes. First, precise instantaneous jump calendar display tag heuer replica large switching time is scheduled for midnight. The power required for this process will slowly build up within hours. Furthermore, LANGE 1 escapement now available eccentric balance weight balance wheel and homemade free omega uk watch sprung. Means provided in the hand-carved balance wheel splint omega replica underneath, 21,600 vibrations per hour. This table also hublot replica retains the reliable double-barrel, power reserve of 72 hours.