Прочитать на английском

Поделиться через


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

Определение

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

public System.DirectoryServices.DirectoryEntry Add (string name, string schemaClassName);

Параметры

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

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

Продукт Версии
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9