DirectoryEntries.Add(String, String) Metoda

Definicja

Tworzy nowy wpis w kontenerze.

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

Parametry

name
String

Nazwa nowego wpisu.

schemaClassName
String

Nazwa schematu używanego dla nowego wpisu.

Zwraca

DirectoryEntry Obiekt reprezentujący nowy wpis.

Wyjątki

Wystąpił błąd podczas wywołania interfejsu bazowego.

Przykłady

Poniższy przykład platformy .NET w języku Visual Basic tworzy nowy DirectoryEntry obiekt z określoną ścieżką, a następnie tworzy nowy wpis w kontenerze i zapisuje go.

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.")  

Poniższy przykład języka C# tworzy nowy DirectoryEntry obiekt z określoną ścieżką, a następnie tworzy nowy wpis w kontenerze i zapisuje go.

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.");  

Poniższy przykład języka C++ tworzy nowy DirectoryEntry obiekt z określoną ścieżką, a następnie tworzy nowy wpis w kontenerze i zapisuje go.

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);  

Uwagi

Aby utworzenie było trwałe, należy wywołać metodę CommitChanges w nowym wpisie. Po wywołaniu tej metody można ustawić obowiązkowe wartości właściwości w nowym wpisie. Dostawcy mają różne wymagania dotyczące właściwości, które należy ustawić przed wywołaniem CommitChanges metody . Jeśli te wymagania nie zostaną spełnione, dostawca może zgłosić wyjątek. Sprawdź u dostawcy, aby określić, które właściwości należy ustawić przed zatwierdzeniem zmian.

Dotyczy