Export (0) Print
Expand All

ConfigurationSection Constructor

Updated: April 2009

Initializes a new instance of the ConfigurationSection class.

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)

protected ConfigurationSection()

To use the ConfigurationSection constructor, you need to define a custom section type first. For an example see the ConfigurationSection class overview.

The following example shows how to use the ConfigurationSection constructor. This example assumes that you have created a custom section class named CustomSection. For an example of such a class, see the ConfigurationSection class overview.

// Create a custom section. 
static void CreateSection()
{
    try
    {

        CustomSection customSection;

        // Get the current configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

        // Create the section entry   
        // in the <configSections> and the  
        // related target section in <configuration>. 
        if (config.Sections["CustomSection"] == null)
        {
            customSection = new CustomSection();
            config.Sections.Add("CustomSection", customSection);
            customSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }

}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Date

History

Reason

April 2009

Added a note about prerequisites for the code example.

Customer feedback.

Community Additions

ADD
Show:
© 2015 Microsoft