DirectoryEntries.Add(String, String) Method

Definition

Cria uma nova entrada no contêiner.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

Parameters

name
String

O nome da nova entrada.The name of the new entry.

schemaClassName
String

O nome do esquema usado para a nova entrada.The name of the schema that is used for the new entry.

Returns

DirectoryEntry

Um objeto DirectoryEntry que representa a nova entrada.A DirectoryEntry object that represents the new entry.

Exceptions

Erro durante a chamada à interface subjacente.An error occurred during the call to the underlying interface.

Examples

O exemplo de Visual Basic .NET a seguir cria um novo objeto DirectoryEntry com um caminho especificado e, em seguida, cria uma nova entrada no contêiner e salva-o.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.")  

O exemplo C# a seguir cria um novo objeto DirectoryEntry com um caminho especificado e, em seguida, cria uma nova entrada no contêiner e salva-o.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.");  

O exemplo C++ a seguir cria um novo objeto DirectoryEntry com um caminho especificado e, em seguida, cria uma nova entrada no contêiner e salva-o.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);  
  

Remarks

Você deve chamar o método CommitChanges na nova entrada para tornar a criação permanente.You must call the CommitChanges method on the new entry to make the creation permanent. Ao chamar esse método, você pode definir valores de propriedade obrigatórios na nova entrada.When you call this method, you can then set mandatory property values on the new entry. Os provedores têm requisitos diferentes para propriedades que precisam ser definidas antes que uma chamada para o método CommitChanges seja feita.The providers each have different requirements for properties that need to be set before a call to the CommitChanges method is made. Se esses requisitos não forem atendidos, o provedor poderá gerar uma exceção.If those requirements are not met, the provider might throw an exception. Verifique com seu provedor para determinar quais propriedades devem ser definidas antes de confirmar as alterações.Check with your provider to determine which properties must be set before committing changes.

Applies to