Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
 Declaring and Accessing Section Gro...
.NET Framework Developer's Guide
Declaring and Accessing Section Groups

You can organize similar sections into groups by using the <sectionGroup> element. Declaring a section group creates a containing element for configuration sections and ensures that there are no naming conflicts with configuration sections that are defined by someone else. Declare the section group in the <configSections> element and put sections that belong to that group in the <sectionGroup> element.

The following example shows how to declare a section group in a configuration file.

<configuration>
    <configSections>
        <section name="sampleSection"
                 type="System.Configuration.SingleTagSectionHandler" />
        <!--The following code declares a section group called mySectionGroup. -->
        <sectionGroup name="mySectionGroup">
            <section name="mySection"
             type="System.Configuration.NameValueSectionHandler,System" />
        </sectionGroup>
    </configSections>

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

</configuration>

To access sections that are within a section group, use the ConfigurationSettings.GetConfig method to specify both the section group name and the section name, as shown in the following example.

[Visual Basic]
Dim nvc As NameValueCollection

' Notice the path-like syntax.
nvc = CType(ConfigurationSettings.GetConfig("mySectionGroup/mySection"),
      NameValueCollection)
[C#]
// Notice the path-like syntax.
NameValueCollection nvc = (NameValueCollection)
   ConfigurationSettings.GetConfig("mySectionGroup/mySection");

See Also

Configuration Section Settings | Declaring and Accessing Custom Configuration Sections | Configuration Sections Schema

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker