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 对象。

例外

调用基础接口时出错。

示例

下面的 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 方法之前设置的属性有不同的要求。 如果不满足这些要求,提供程序可能会引发异常。 请咨询提供程序,确定在提交更改之前必须设置哪些属性。

适用于