ConfigurationSection Constructor ()

 

Initializes a new instance of the ConfigurationSection class.

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

Protected Sub New

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.
Shared Sub CreateSection()
   Try

      Dim customSection As CustomSection

      ' Get the current configuration file.
         Dim config As System.Configuration.Configuration = _
         ConfigurationManager.OpenExeConfiguration( _
         ConfigurationUserLevel.None)

      ' Create the section entry  
      ' in the <configSections> and the 
      ' related target section in <configuration>.
      If config.Sections("CustomSection") Is Nothing Then
         customSection = New CustomSection()
         config.Sections.Add("CustomSection", customSection)
         customSection.SectionInformation.ForceSave = True
         config.Save(ConfigurationSaveMode.Full)
      End If
   Catch err As ConfigurationErrorsException
      Console.WriteLine(err.ToString())
   End Try
End Sub 'CreateSection

.NET Framework
Available since 2.0
Return to top
Show: