DirectoryEntries.Find Metoda

Definicja

Zwraca element członkowski tej kolekcji.

Przeciążenia

Find(String)

Zwraca element członkowski tej kolekcji o określonej nazwie.

Find(String, String)

Zwraca element członkowski tej kolekcji o określonej nazwie i określonym typie.

Find(String)

Źródło:
DirectoryEntries.cs
Źródło:
DirectoryEntries.cs
Źródło:
DirectoryEntries.cs

Zwraca element członkowski tej kolekcji o określonej nazwie.

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

Parametry

name
String

Zawiera nazwę obiektu podrzędnego, dla którego ma być wyszukiwane.

Zwraca

Obiekt DirectoryEntry reprezentujący znaleziony obiekt podrzędny.

Wyjątki

Obiekt Active Directory Domain Services nie jest kontenerem.

Wystąpił błąd podczas wywołania podstawowego interfejsu.

Uwagi

Jeśli obiekty podrzędne różnych typów mają taką samą nazwę, zwracany jest pierwszy pasujący obiekt podrzędny.

Uwaga

Dostawca usług Internet Information Services (IIS) nie obsługuje tej metody. Użyj metody przeciążonej Find i określ pusty ciąg ("") dla parametru schemaClassName .

Jeśli nie zostanie znaleziony pasujący wynik, DirectoryServicesCOMException zostanie zgłoszony kod błędu 0x2030.

Dotyczy

Find(String, String)

Źródło:
DirectoryEntries.cs
Źródło:
DirectoryEntries.cs
Źródło:
DirectoryEntries.cs

Zwraca element członkowski tej kolekcji o określonej nazwie i określonym typie.

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

Parametry

name
String

Nazwa obiektu katalogu podrzędnego, dla którego ma być wyszukiwane.

schemaClassName
String

Nazwa klasy obiektu katalogu podrzędnego, dla którego ma być wyszukiwane.

Zwraca

Obiekt DirectoryEntry reprezentujący znaleziony obiekt podrzędny.

Wyjątki

Obiekt Active Directory Domain Services nie jest kontenerem.

Wystąpił błąd podczas wywołania podstawowego interfejsu.

Przykłady

Poniższy przykład platformy .NET w języku Visual Basic tworzy nowy DirectoryEntry obiekt z określoną ścieżką, a następnie tworzy nowy wpis w kontenerze i zapisuje go. Próbuje pobrać nowo utworzony wpis.

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  

W poniższym przykładzie w języku C# pokazano, jak utworzyć nowy DirectoryEntry obiekt z określoną ścieżką, a następnie utworzyć nowy wpis w kontenerze i zapisać go. Próbuje pobrać nowo utworzony wpis.

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);  
      }  
   }  
}  

Poniższy przykład w języku C++ tworzy nowy DirectoryEntry obiekt z określoną ścieżką, a następnie tworzy nowy wpis w kontenerze i zapisuje go. Próbuje pobrać nowy wpis.

#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);  
    }  
}  

Uwagi

Jeśli nie zostanie znaleziony pasujący wynik, DirectoryServicesCOMException zostanie zgłoszony kod błędu 0x2030.

Dotyczy