This topic has not yet been rated - Rate this topic

ConfigurationSection Constructor

Initializes a new instance of the ConfigurationSection class.

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

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.
        static void CreateSection()
        {
            try
            {

                CustomSection customSection;

                // Get the current configuration file.
                System.Configuration.Configuration config =
                        ConfigurationManager.OpenExeConfiguration(
                        ConfigurationUserLevel.None);

                // Create the section entry  
                // in the <configSections> and the 
                // related target section in <configuration>.
                if (config.Sections["CustomSection"] == null)
                {
                    customSection = new CustomSection();
                    config.Sections.Add("CustomSection", customSection);
                    customSection.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);
                }
            }
            catch (ConfigurationErrorsException err)
            {
                Console.WriteLine(err.ToString());
            }

        }



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
ConfigurationSection or CustomSection

Estoy tratando de utilizar este codigo fuente, pero no funciona.
Al parecer en la declaración de la variable CustomSection customSection; debe ser ConfigurationSection. 
Sin embargo ConfigurationSection es una clase abstracta y no se podrá crear una nueva instancia. Cuando lo instancian despues del if.

Les agradezco su respuesta.

Buen día.