Share via


ConfigurationElementCollection.CreateNewElement(String) Method

Definition

Creates a new element for the current collection.

protected:
 override Microsoft::Web::Administration::ConfigurationElement ^ CreateNewElement(System::String ^ elementTagName);
protected override Microsoft.Web.Administration.ConfigurationElement CreateNewElement (string elementTagName);
override this.CreateNewElement : string -> Microsoft.Web.Administration.ConfigurationElement
Protected Overrides Function CreateNewElement (elementTagName As String) As ConfigurationElement

Parameters

elementTagName
String

The name of the element to create.

Returns

A reference to the new ConfigurationElement object that was created.

Examples

The following example demonstrates the CreateNewElement method. This example sets several attribute values and adds the newly created element to the element collection. This code example is part of a larger example provided for the ConfigurationElement class.

// Use any of the following lines to set the attribute value.
// attribute.Value = "TestDemo(Modified)";
moduleproviderelement.SetAttributeValue(
    "name", "TestDemo(Modified)");
// moduleproviderelement["name"] = "TestDemo(Modified)";

Remarks

Override the CreateNewElement method to create custom ConfigurationElement objects of a specific type. When a collection is loaded from the configuration file, CreateNewElement is called to create individual elements. CreateNewElement must be overridden in classes that derive from the ConfigurationElementCollection class.

After an element is created, the attributes of the element must be set and the element must be added to the element collection.

When a configuration element is added to the ConfigurationElementCollection object and updated with the Update method, it is stored in the Administration.config file.

When the configuration element is created, it must be created with a unique name attribute. If the name attribute is not unique, an error occurs.

Applies to