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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.