This documentation is archived and is not being maintained.

ConfigurationManager.GetSection Method

Retrieves a specified configuration section for the current application's default configuration.

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

public static Object GetSection (
	string sectionName
public static Object GetSection (
	String sectionName
public static function GetSection (
	sectionName : String
) : Object
Not applicable.



The configuration section path and name.

Return Value

The specified ConfigurationSection object, or a null reference (Nothing in Visual Basic) if the section does not exist.

Exception typeCondition


A configuration file could not be loaded.

For client applications, this method retrieves a configuration file obtained by merging the application configuration file, the local user configuration file, and the roaming configuration file.

The GetSection method accesses run-time configuration information that it cannot change. To change the configuration, you use the GetSection method on the configuration file that you obtain by using one of the following Open methods:

Notes to Implementers: You must cast the return value to the expected configuration type. To avoid possible casting exceptions, you should use a conditional casting operation such as the as operator in C# or the TryCast function in Visual Basic.

The following code example shows how to use the GetSection method.

This code example is part of a larger example provided for the ConfigurationManager class

// Show how to use GetSection.
static void DisplayAppSettingsSectionRawXml()

    // Get the configuration file.
    System.Configuration.Configuration config =

    // Get the AppSetins section.
    AppSettingsSection appSettingSection = 

    // Display raw xml.


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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0