共用方式為


DirectoryEntries.Add(String, String) 方法

定義

在容器 (Container) 中建立新項目。

public:
 System::DirectoryServices::DirectoryEntry ^ Add(System::String ^ name, System::String ^ schemaClassName);
public System.DirectoryServices.DirectoryEntry Add (string name, string schemaClassName);
member this.Add : string * string -> System.DirectoryServices.DirectoryEntry
Public Function Add (name As String, schemaClassName As String) As DirectoryEntry

參數

name
String

新項目的名稱。

schemaClassName
String

新項目所使用的結構描述 (Schema) 名稱。

傳回

DirectoryEntry 物件,表示新項目。

例外狀況

呼叫基礎介面期間發生錯誤。

範例

下列 Visual Basic .NET 範例會建立具有指定路徑的新 DirectoryEntry 物件,然後在容器中建立新的專案並加以儲存。

Dim strPath As String = "IIS://localhost/W3SVC/1/Root"  
' Create a new 'DirectoryEntry' object with the given path.  
Dim myDE As New DirectoryEntry(strPath)  
Dim myEntries As DirectoryEntries = myDE.Children  
' Create a new entry 'Sample' in the container.  
Dim myDirectoryEntry As DirectoryEntry = myEntries.Add("CN=Sample", myDE.SchemaClassName)  
' Save changes of entry in the 'Active Directory Domain Services'.  
myDirectoryEntry.CommitChanges()  
Console.WriteLine(myDirectoryEntry.Name + " entry is created in container.")  

下列 C# 範例會建立具有指定路徑的新 DirectoryEntry 物件,然後在容器中建立新的專案並加以儲存。

String strPath = "IIS://localhost/W3SVC/1/Root";  

// Create a new 'DirectoryEntry' object with the given path.  
DirectoryEntry myDE = new DirectoryEntry(strPath);  
DirectoryEntries myEntries = myDE.Children;  

// Create a new entry 'Sample' in the container.  
DirectoryEntry myDirectoryEntry =   
   myEntries.Add("CN=Sample", myDE.SchemaClassName);  
// Save changes of entry in the 'Active Directory Domain Services'.  
myDirectoryEntry.CommitChanges();  
Console.WriteLine (myDirectoryEntry.Name + " entry is created in container.");  

下列 C++ 範例會建立具有指定路徑的新 DirectoryEntry 物件,然後在容器中建立新的專案並加以儲存。

String* strPath = S"IIS://localhost/W3SVC/1/Root";  

// Create a new 'DirectoryEntry' object with the given path.  
DirectoryEntry* myDE = new DirectoryEntry(strPath);  
DirectoryEntries* myEntries = myDE->Children;  

// Create a new entry 'Sample' in the container.  
DirectoryEntry* myDirectoryEntry = myEntries->Add(S"CN=Sample", myDE->SchemaClassName);  
// Save changes of entry in the 'Active Directory Domain Services'.  
myDirectoryEntry->CommitChanges();  
Console::WriteLine("{0} entry is created in container.", myDirectoryEntry->Name);  

備註

您必須在新的專案上呼叫 CommitChanges 方法,才能永久建立。 當您呼叫這個方法時,就可以在新的項目上設定強制屬性值。 提供者對於在呼叫 CommitChanges 方法之前必須設定的屬性都有不同的需求。 如果不符合這些需求,提供者可能會擲回例外狀況。 請洽詢您的提供者,以判斷在認可變更之前必須設定哪些屬性。

適用於