ConfigurationManager::GetSection Method (String^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

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

static Object^ GetSection(
	String^ sectionName


Type: System::String^

The configuration section path and name.

Return Value

Type: System::Object^

The specified ConfigurationSection object, or null if the section does not exist.

Exception Condition

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 function in Visual Basic.

The following example shows how to use the GetSection method. The example is part of a larger example that is provided for the ConfigurationManager class.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top