learned/learning/to learn RSS 2.0
# Monday, June 1, 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:


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



Step 2

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


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

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



Your app.config will be like this


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



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



  <!--<Custom Seciton>-->


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

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




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







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>


<sectionGroup name ="customSectionGroup">

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

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




Add this around your custom section:



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

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



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

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




To access it, just change the path:

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


customSectionGroup/customSection1 or customSectionGroup/customSection2


Monday, June 1, 2009 6:43:34 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Comments are closed.
<May 2020>
About the author/Disclaimer

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

© Copyright 2020
Sign In
Total Posts: 41
This Year: 0
This Month: 0
This Week: 0
Comments: 47
Pick a theme:
All Content © 2020, 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.