DirectoryEntries.Find 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回此集合的一个成员。
重载
Find(String) |
返回此集合中具有指定名称的成员。 |
Find(String, String) |
返回此集合中具有指定名称和指定类型的成员。 |
Find(String)
返回此集合中具有指定名称的成员。
public:
System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name);
public System.DirectoryServices.DirectoryEntry Find (string name);
member this.Find : string -> System.DirectoryServices.DirectoryEntry
Public Function Find (name As String) As DirectoryEntry
参数
- name
- String
包含要搜索的子对象的名称。
返回
DirectoryEntry,表示找到的子对象。
例外
Active Directory 域服务对象不是容器。
调用基础接口时出错。
注解
如果不同类型的子对象具有相同的名称,则返回第一个匹配的子对象。
备注
Internet Information Services (IIS) 提供程序不支持此方法。 使用重载 Find 的方法并为参数指定空字符串 (“”) schemaClassName
。
如果未找到匹配的结果, DirectoryServicesCOMException 则会引发错误代码0x2030。
适用于
Find(String, String)
返回此集合中具有指定名称和指定类型的成员。
public:
System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name, System::String ^ schemaClassName);
public System.DirectoryServices.DirectoryEntry Find (string name, string schemaClassName);
public System.DirectoryServices.DirectoryEntry Find (string name, string? schemaClassName);
member this.Find : string * string -> System.DirectoryServices.DirectoryEntry
Public Function Find (name As String, schemaClassName As String) As DirectoryEntry
参数
- name
- String
要搜索的子目录对象的名称。
- schemaClassName
- String
要搜索的子目录对象的类名。
返回
一个 DirectoryEntry 对象,表示找到的子对象。
例外
Active Directory 域服务对象不是容器。
调用基础接口时出错。
示例
以下Visual Basic .NET 示例创建具有指定路径的新DirectoryEntry对象,然后在容器中创建一个新条目并将其保存。 它尝试检索新创建的条目。
Try
Dim myEntry1 As DirectoryEntry
Dim myEntry2 As DirectoryEntry
Dim strPath As String = "LDAP://DC=fabrikam,DC=com"
' Create a 'DirectoryEntry' object with the given path.
Dim myDE As New DirectoryEntry(strPath)
Dim myEntries As DirectoryEntries = myDE.Children
' Create a new entry in the container.
myEntry1 = myEntries.Add("CN=Sample Entry", myDE.SchemaClassName)
' Save changes in the 'Active Directory Domain Services' store.
myEntry1.CommitChanges()
' Find a child in the 'DirectoryEntries' collection which has the
' specified name and type.
myEntry2 = myEntries.Find("CN=Sample Entry", myDE.SchemaClassName)
Console.WriteLine(myEntry2.Name + " is found in container.")
Catch e As Exception
Console.WriteLine("The following exception was raised : {0}", e.Message.ToString())
End Try
以下 C# 示例演示如何使用指定路径创建新 DirectoryEntry 对象,然后在容器中创建一个新条目并将其保存。 它尝试检索新创建的条目。
using System;
using System.DirectoryServices;
class MyClass1
{
static void Main()
{
try
{
DirectoryEntry myEntry1;
DirectoryEntry myEntry2;
String strPath = "LDAP://DC=fabrikam,DC=com";
// Create a 'DirectoryEntry' object with the given path.
DirectoryEntry myDE = new DirectoryEntry(strPath);
DirectoryEntries myEntries = myDE.Children;
// Create a new entry in the container.
myEntry1 = myEntries.Add("CN=Sample Entry",myDE.SchemaClassName);
// Save changes in the 'Active Directory Domain Services' store.
myEntry1.CommitChanges();
// Find a child in the 'DirectoryEntries' collection which has the
// specified name and type.
myEntry2 = myEntries.Find("CN=Sample Entry",myDE.SchemaClassName);
Console.WriteLine (myEntry2.Name + " is found in container.");
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",e.Message);
}
}
}
以下 C++ 示例使用指定的路径创建一个新 DirectoryEntry 对象,然后在容器中创建一个新条目并将其保存。 它尝试检索新条目。
#using <mscorlib.dll>
#using <System.dll>
#using <System.Directoryservices.dll>
using namespace System;
using namespace System::DirectoryServices;
int main() {
try {
DirectoryEntry* myEntry1;
DirectoryEntry* myEntry2;
String* strPath = S"LDAP://DC=fabrikam,DC=com";
// Create a 'DirectoryEntry' object with the given path.
DirectoryEntry* myDE = new DirectoryEntry(strPath);
DirectoryEntries* myEntries = myDE->Children;
// Create a new entry in the container.
myEntry1 = myEntries->Add(S"CN=Sample Entry", myDE->SchemaClassName);
// Save changes in the 'Active Directory Domain Services' store.
myEntry1->CommitChanges();
// Find a child in the 'DirectoryEntries' collection which has the
// specified name and type.
myEntry2 = myEntries->Find(S"CN=Sample Entry", myDE->SchemaClassName);
Console::WriteLine ("{0} is found in container.", myEntry2->Name);
} catch(Exception* e) {
Console::WriteLine("The following exception was raised : {0}", e->Message);
}
}
注解
如果未找到匹配的结果, DirectoryServicesCOMException 则会引发错误代码0x2030。