Create Custom Configuration Sections

Problem

You want to use a custom configuration setting to organize related custom settings.

Solution

Register your custom setting with the System.Configuration.NameValueSectionHandler class. You can then use the shared ConfigurationSettings.GetConfig method to retrieve a collection of settings from the section.

Discussion

.NET uses an extensible system of configuration file settings. You have multiple options for reading custom settings from a configuration file:

  • Place your custom settings in the <appSettings> group, and access them through the ConfigurationSettings.AppSettings collection. This approach was used in recipe Read Application Configuration Settings.

  • Create your own custom section handler by implementing ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.