ConfigurationSection Constructor ()

 

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());
    }

}

.NET Framework
Available since 2.0
Return to top
Show: