Updated: April 2009
Namespace:
System.Configuration
Assembly:
System.Configuration (in System.Configuration.dll)
Visual Basic (Declaration)
Public Function GetSection ( _
sectionName As String _
) As ConfigurationSection
Dim instance As Configuration
Dim sectionName As String
Dim returnValue As ConfigurationSection
returnValue = instance.GetSection(sectionName)
public ConfigurationSection GetSection(
string sectionName
)
public:
ConfigurationSection^ GetSection(
String^ sectionName
)
public function GetSection(
sectionName : String
) : ConfigurationSection
Configuration settings are contained within sections that group similar settings together for convenience. The GetSection method retrieves a configuration section by its name.
The following code example demonstrates how to use the GetSection method to access custom section information. This example assumes that you have created a custom section class named CustomSection. For an example of such a class, see the Configuration class overview.
' Get a custom section.
Shared Sub GetSection()
Try
Dim customSection As CustomSection
' Get the current configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
customSection = _
config.GetSection("CustomSection")
Console.WriteLine( _
"Section name: {0}", _
customSection.SectionInformation.Name)
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub 'GetSection
// Get a custom section.
static void GetSection()
{
try
{
CustomSection customSection;
// Get the current configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None) as Configuration;
customSection =
config.GetSection("CustomSection") as CustomSection;
Console.WriteLine("Section name: {0}",
customSection.SectionInformation.Name);
}
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
Reference
Date | History | Reason |
|---|
April 2009
| Added a note about prerequisites for running the code example. |
Customer feedback.
|