ConfigurationElement Class
IIS 7.0
Represents an element in a configuration file.
Namespace:
Microsoft.Web.Administration
Assembly: Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)
The ConfigurationElement type exposes the following members.
| Name | Description | |
|---|---|---|
|
ConfigurationElement | Initializes a new instance of the ConfigurationElement class. |
| Name | Description | |
|---|---|---|
|
Attributes | Gets a configuration attribute collection that contains the list of attributes for this element. |
|
ChildElements | Gets all the child elements of the current element. |
|
ElementTagName | Gets the XML tag name of the current element. |
|
IsLocallyStored | Gets a value indicating whether the configuration element is stored in a particular configuration file. |
|
Item | Gets or sets an attribute with the specified name. |
|
Methods | Gets a collection of methods for the configuration element. |
|
RawAttributes | Gets the raw attribute names and values for the current configuration element. |
|
Schema | Gets the schema for the current element. |
| Name | Description | |
|---|---|---|
|
Delete | |
|
Equals | (Inherited from Object.) |
|
Finalize | (Inherited from Object.) |
|
GetAttribute | Returns a ConfigurationAttribute object that represents the requested attribute. |
|
GetAttributeValue | Returns the value of the specified attribute. |
|
GetChildElement(String) | Returns a child element that is under the current configuration element and has the specified name. |
|
GetChildElement(String, Type) | Returns a child element that is under the current configuration element and has the specified name and type. |
|
GetCollection()()()() | Returns the default collection for the current configuration element. |
|
GetCollection(String) | Returns all configuration elements that belong to the current configuration element. |
|
GetCollection(Type) | Returns the configuration element that has the specified type and is under the current configuration element. |
|
GetCollection(String, Type) | Returns the configuration element that has the specified name and type and is under the current configuration element. |
|
GetHashCode | (Inherited from Object.) |
|
GetMetadata | Returns metadata values from the element schema. |
|
GetType | (Inherited from Object.) |
|
MemberwiseClone | (Inherited from Object.) |
|
SetAttributeValue | Sets the value of the specified attribute. |
|
SetMetadata | Sets metadata values from the element schema. |
|
ToString | (Inherited from Object.) |
The following example implements several of the methods and properties of the ConfigurationElement class. This example obtains a ConfigurationSection object for the moduleProvider section and gets a ConfigurationElementCollection from that section. This example iterates through each ConfigurationElement of the retrieved collection.
[ModuleServiceMethod(PassThrough = true)] public ArrayList GetElementCollection() { // Use an ArrayList to transfer objects to the client. ArrayList arrayOfConfigPropertyBags = new ArrayList(); ServerManager serverManager = new ServerManager(); Configuration administrationConfig = serverManager.GetAdministrationConfiguration(); ConfigurationSection moduleProvidersSection = administrationConfig.GetSection("moduleProviders"); ConfigurationElementCollection elementCollection = moduleProvidersSection.GetCollection(); // If there is a configuration element with the name of TestDemo(Modified), delete it. ConfigurationElement elementtoremove = null; foreach (ConfigurationElement moduleproviderelement in elementCollection) { if(moduleproviderelement.Attributes["name"].Value.ToString() == "TestDemo(Modified)") { elementtoremove = moduleproviderelement; } } if (elementtoremove != null) { elementCollection.Remove(elementtoremove); } foreach (ConfigurationElement moduleproviderelement in elementCollection) { PropertyBag elementBag = new PropertyBag(); elementBag[ConfigurationDemoGlobals.SchemaName] = moduleproviderelement.Schema.Name; elementBag[ConfigurationDemoGlobals.ElementTagName] = moduleproviderelement.ElementTagName; ArrayList attributeArrayList = new ArrayList(); // Loop through all attributes in the element attribute list. // Get the attribute name and value. foreach (ConfigurationAttribute attribute in moduleproviderelement.Attributes) { PropertyBag attributeBag = new PropertyBag(); attributeBag[ConfigurationDemoGlobals.AttributeName] = attribute.Name; attributeBag[ConfigurationDemoGlobals.AttributeValue] = attribute.Value; // Change the value of the provider name "TestDemo" to "TestDemo(Modified)". if (attribute.Value.ToString() == "TestDemo") { // Use any of the following lines to set the attribute value. // attribute.Value = "TestDemo(Modified)"; moduleproviderelement.SetAttributeValue( "name", "TestDemo(Modified)"); // moduleproviderelement["name"] = "TestDemo(Modified)"; // Use any of the following lines to retrieve the attribute value. // attributeBag[ConfigurationDemoGlobals.AttributeName] = "name"; attributeBag[ConfigurationDemoGlobals.AttributeName] = moduleproviderelement.GetAttributeValue("name"); // attributeBag[ConfigurationDemoGlobals.AttributeName] = // moduleproviderelement["name"]; // Set the element's lockItem attribute. moduleproviderelement.SetMetadata("lockItem", true); // persisted in Administration.config } attributeArrayList.Add(attributeBag); } elementBag[ConfigurationDemoGlobals.AttributeArrayList] = attributeArrayList; arrayOfConfigPropertyBags.Add(elementBag); } // Create a new element. It must have a unique name. ConfigurationElement newelement; bool newelementexists = false; foreach (ConfigurationElement element in elementCollection) { if (element.Attributes["name"].Value.ToString() == "TestDemo") { newelementexists = true; } } if (!newelementexists) { newelement = elementCollection.CreateElement("add"); newelement.Attributes["name"].Value = "TestDemo"; newelement.Attributes["Type"].Value = "TestDemo.TestDemoModuleProvider, TestDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=104f78e73dc54601"; elementCollection.Add(newelement); } // CommitChanges to persist the changes to Administration.config. serverManager.CommitChanges(); return arrayOfConfigPropertyBags; }
System..::..Object
Microsoft.Web.Administration..::..ConfigurationElement
Microsoft.Web.Administration..::..Application
Microsoft.Web.Administration..::..ApplicationDefaults
Microsoft.Web.Administration..::..ApplicationDomain
Microsoft.Web.Administration..::..ApplicationPool
Microsoft.Web.Administration..::..ApplicationPoolCpu
Microsoft.Web.Administration..::..ApplicationPoolDefaults
Microsoft.Web.Administration..::..ApplicationPoolFailure
Microsoft.Web.Administration..::..ApplicationPoolPeriodicRestart
Microsoft.Web.Administration..::..ApplicationPoolProcessModel
Microsoft.Web.Administration..::..ApplicationPoolRecycling
Microsoft.Web.Administration..::..Binding
Microsoft.Web.Administration..::..ConfigurationElementCollectionBase<(Of <(<'T>)>)>
Microsoft.Web.Administration..::..ConfigurationSection
Microsoft.Web.Administration..::..Request
Microsoft.Web.Administration..::..Schedule
Microsoft.Web.Administration..::..Site
Microsoft.Web.Administration..::..SiteDefaults
Microsoft.Web.Administration..::..SiteLimits
Microsoft.Web.Administration..::..SiteLogFile
Microsoft.Web.Administration..::..SiteTraceFailedRequestsLogging
Microsoft.Web.Administration..::..VirtualDirectory
Microsoft.Web.Administration..::..VirtualDirectoryDefaults
Microsoft.Web.Administration..::..WorkerProcess
Microsoft.Web.Administration..::..ConfigurationElement
Microsoft.Web.Administration..::..Application
Microsoft.Web.Administration..::..ApplicationDefaults
Microsoft.Web.Administration..::..ApplicationDomain
Microsoft.Web.Administration..::..ApplicationPool
Microsoft.Web.Administration..::..ApplicationPoolCpu
Microsoft.Web.Administration..::..ApplicationPoolDefaults
Microsoft.Web.Administration..::..ApplicationPoolFailure
Microsoft.Web.Administration..::..ApplicationPoolPeriodicRestart
Microsoft.Web.Administration..::..ApplicationPoolProcessModel
Microsoft.Web.Administration..::..ApplicationPoolRecycling
Microsoft.Web.Administration..::..Binding
Microsoft.Web.Administration..::..ConfigurationElementCollectionBase<(Of <(<'T>)>)>
Microsoft.Web.Administration..::..ConfigurationSection
Microsoft.Web.Administration..::..Request
Microsoft.Web.Administration..::..Schedule
Microsoft.Web.Administration..::..Site
Microsoft.Web.Administration..::..SiteDefaults
Microsoft.Web.Administration..::..SiteLimits
Microsoft.Web.Administration..::..SiteLogFile
Microsoft.Web.Administration..::..SiteTraceFailedRequestsLogging
Microsoft.Web.Administration..::..VirtualDirectory
Microsoft.Web.Administration..::..VirtualDirectoryDefaults
Microsoft.Web.Administration..::..WorkerProcess