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 表示新条目的对象。

例外

调用基础接口期间发生错误。

示例

以下示例使用指定的路径创建一个新 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.")
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.");

注解

必须在新条目上调用 CommitChanges 该方法,以使创建永久化。 调用此方法时,可以在新条目上设置必需属性值。 提供程序对在调用 CommitChanges 方法之前需要设置的属性有不同的要求。 如果未满足这些要求,提供程序可能会引发异常。 请与提供程序联系,以确定在提交更改之前必须设置哪些属性。

适用于