DirectoryEntries.Add(String, String) Metodo

Definizione

Crea una nuova voce nel contenitore.

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

Parametri

name
String

Nome della nuova voce.

schemaClassName
String

Nome dello schema utilizzato per la nuova voce.

Valori restituiti

Oggetto DirectoryEntry che rappresenta la nuova voce.

Eccezioni

Si è verificato un errore durante la chiamata all'interfaccia sottostante.

Esempio

Nell'esempio seguente viene creato un nuovo DirectoryEntry oggetto con un percorso specificato, quindi viene creata una nuova voce nel contenitore e salvata.

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

Commenti

È necessario chiamare il CommitChanges metodo sulla nuova voce per rendere permanente la creazione. Quando si chiama questo metodo, è possibile impostare i valori di proprietà obbligatori nella nuova voce. I provider hanno requisiti diversi per le proprietà che devono essere impostate prima che venga effettuata una chiamata al CommitChanges metodo . Se tali requisiti non sono soddisfatti, il provider potrebbe generare un'eccezione. Rivolgersi al provider per determinare quali proprietà devono essere impostate prima di eseguire il commit delle modifiche.

Si applica a