DirectoryEntries.Add(String, String) DirectoryEntries.Add(String, String) DirectoryEntries.Add(String, String) DirectoryEntries.Add(String, String) Method

定義

在容器 (Container) 中建立新項目。Creates a new entry in the 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 String String String

新項目的名稱。The name of the new entry.

schemaClassName
String String String String

新項目所使用的結構描述 (Schema) 名稱。The name of the schema that is used for the new entry.

傳回

DirectoryEntry 物件,表示新項目。A DirectoryEntry object that represents the new entry.

例外狀況

呼叫基礎介面期間發生錯誤。An error occurred during the call to the underlying interface.

範例

下列 Visual Basic .net 範例會使用指定的DirectoryEntry路徑建立新的物件, 然後在容器中建立新的專案並加以儲存。The following Visual Basic .NET example creates a new DirectoryEntry object with a specified path, then creates a new entry in the container and saves it.

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路徑的新物件, 然後在容器中建立新的專案並加以儲存。The following C# example creates a new DirectoryEntry object with a specified path, then creates a new entry in the container and saves it.

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路徑的新物件, 然後在容器中建立新的專案並加以儲存。The following C++ example creates a new DirectoryEntry object with a specified path, then creates a new entry in the container and saves it.

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的專案上呼叫方法, 才能永久建立。You must call the CommitChanges method on the new entry to make the creation permanent. 當您呼叫這個方法時, 就可以在新的專案上設定強制屬性值。When you call this method, you can then set mandatory property values on the new entry. 對於必須在呼叫CommitChanges方法之前設定的屬性, 每個提供者都有不同的需求。The providers each have different requirements for properties that need to be set before a call to the CommitChanges method is made. 如果不符合這些需求, 提供者可能會擲回例外狀況。If those requirements are not met, the provider might throw an exception. 請洽詢您的提供者, 以判斷在認可變更之前必須設定的屬性。Check with your provider to determine which properties must be set before committing changes.

適用於