DirectoryEntries.Find DirectoryEntries.Find DirectoryEntries.Find DirectoryEntries.Find Method

定义

返回此集合的一个成员。Returns a member of this collection.

重载

Find(String) Find(String) Find(String) Find(String)

返回此集合中具有指定名称的成员。Returns the member of this collection with the specified name.

Find(String, String) Find(String, String) Find(String, String) Find(String, String)

返回此集合中具有指定名称和指定类型的成员。Returns the member of this collection with the specified name and of the specified type.

Find(String) Find(String) Find(String) Find(String)

返回此集合中具有指定名称的成员。Returns the member of this collection with the specified name.

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 String String String

包含要搜索的子对象的名称。Contains the name of the child object for which to search.

返回

DirectoryEntry,表示找到的子对象。A DirectoryEntry that represents the child object that was found.

异常

Active Directory 域服务对象不是容器。The Active Directory Domain Services object is not a container.

调用基础接口时出错。An error occurred during the call to the underlying interface.

注解

如果不同类型的子对象具有相同的名称, 则返回第一个匹配的子对象。If child objects of different types have the same name, the first matching child object is returned.

备注

Internet Information Services (IIS) 提供程序不支持此方法。The Internet Information Services (IIS) provider does not support this method. 使用重载Find方法, 并schemaClassName为参数指定一个空字符串 ("")。Use the overloaded Find method and specify an empty string ("") for the schemaClassName parameter.

如果未找到匹配的结果, 则DirectoryServicesCOMException会引发带有错误代码0x2030 的。If no matching result is found, a DirectoryServicesCOMException with error code 0x2030 is thrown.

Find(String, String) Find(String, String) Find(String, String) Find(String, String)

返回此集合中具有指定名称和指定类型的成员。Returns the member of this collection with the specified name and of the specified type.

public:
 System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name, System::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 String String String

要搜索的子目录对象的名称。The name of the child directory object for which to search.

schemaClassName
String String String String

要搜索的子目录对象的类名。The class name of the child directory object for which to search.

返回

一个 DirectoryEntry 对象,表示找到的子对象。A DirectoryEntry object that represents the child object that was found.

异常

Active Directory 域服务对象不是容器。The Active Directory Domain Services object is not a container.

调用基础接口时出错。An error occurred during the call to the underlying interface.

示例

下面的 Visual Basic .net 示例使用指定的DirectoryEntry路径创建一个新的对象, 然后在该容器中创建一个新项并将其保存。The following Visual Basic .NET example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. 它尝试检索新创建的条目。It attempts to retrieve the newly created entry.

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创建一个新的对象, 然后在该容器中创建一个新项并将其保存。The following C# example shows how to create a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. 它尝试检索新创建的条目。It attempts to retrieve the newly- created entry.

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路径创建一个新的对象, 然后在该容器中创建一个新项并将其保存。The following C++ example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. 它尝试检索新条目。It attempts to retrieve the new entry.

#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 的。If no matching result is found, a DirectoryServicesCOMException with error code 0x2030 is thrown.

适用于