Share via


ConfigurationElementCollection.CreateNewElement(String) 方法

定義

建立目前集合的新專案。

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

參數

elementTagName
String

要建立的項目名稱。

傳回

已建立之新 ConfigurationElement 物件的參考。

範例

下列範例示範 CreateNewElement 方法。 本範例會設定數個屬性值,並將新建立的專案加入至專案集合。 此程式碼範例是提供給 類別之較大範例的 ConfigurationElement 一部分。

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

備註

CreateNewElement覆寫 方法來建立特定類型的自訂 ConfigurationElement 物件。 從組態檔載入集合時, CreateNewElement 會呼叫 來建立個別專案。 CreateNewElement 必須在衍生自 類別的 ConfigurationElementCollection 類別中覆寫。

建立專案之後,必須設定元素的屬性,而且元素必須加入至專案集合。

當組態專案新增至 物件, ConfigurationElementCollection 並使用 方法更新 Update 時,它會儲存在Administration.config檔案中。

建立組態專案時,必須使用唯一的名稱屬性加以建立。 如果 name 屬性不是唯一的,就會發生錯誤。

適用於