ConfigurationSectionCollection.Remove Method (String)

 

Removes the specified ConfigurationSection object from this ConfigurationSectionCollection object.

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

public void Remove(
	string name
)

Parameters

name
Type: System.String

The name of the section to be removed.

The following example shows how to use the Remove method.

static void Remove()
{

    try
    {
        System.Configuration.Configuration config =
        ConfigurationManager.OpenExeConfiguration(
        ConfigurationUserLevel.None);

        CustomSection customSection =
            config.GetSection(
            "CustomSection") as CustomSection;


        if (customSection != null)
        {
            config.Sections.Remove("CustomSection");
            customSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);
        }
        else
            Console.WriteLine(
                "CustomSection does not exists.");

    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}

.NET Framework
Available since 2.0
Return to top
Show: