DirectoryEntries.Add(String, String) Метод

Определение

Создает новый элемент в контейнере.

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

Имя схемы, используемой для нового элемента.

Возвращаемое значение

Объект 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 метода . Если эти требования не выполняются, поставщик может создать исключение. Обратитесь к поставщику, чтобы определить, какие свойства необходимо задать перед фиксацией изменений.

Применяется к