SearchResult Klass

Definition

Klassen SearchResult kapslar in en nod i Doménové služby Active Directory-hierarkin som returneras under en sökning via DirectorySearcher.

public ref class SearchResult
public class SearchResult
type SearchResult = class
Public Class SearchResult
Arv
SearchResult

Exempel

I följande exempel skapas ett nytt DirectoryEntry objekt med önskad sökväg och metoden används FindOne för att initiera sökningen. När sökningen har utförts använder GetDirectoryEntry exemplet metoden för att hämta den livekatalogpost som identifieras i sökresultaten.

Imports System
Imports System.DirectoryServices
Imports Microsoft.VisualBasic

Public Class MySample
   Public Shared Sub Main()
      Dim myLDAPPath As String = ""
      Try
         ' Create a 'DirectoryEntry' object to search.
         Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')")
         myLDAPPath = Console.ReadLine()
         Dim mySearchRoot As New DirectoryEntry(myLDAPPath)

         Dim myDirectorySearcher As New DirectorySearcher(mySearchRoot)

         ' Get the first entry of the search.
         Dim mySearchResult As SearchResult = myDirectorySearcher.FindOne()
         If Not (mySearchResult Is Nothing) Then
            ' Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
            Dim myDirectoryEntry As DirectoryEntry = mySearchResult.GetDirectoryEntry()
            Console.WriteLine(ControlChars.Newline + "The name of the 'myDirectoryEntry' " + _
                        "directory entry that corresponds to the " + _
                        "'mySearchResult' search result is : {0}" + _
                        ControlChars.Newline, myDirectoryEntry.Name)
            Dim mySearchResultPath As String = mySearchResult.Path
            Console.WriteLine("The path for the 'mySearchResult' search result is : {0}" + _
                              ControlChars.Newline, mySearchResultPath)
            ' Get the properties of the 'mySearchResult'.
            Dim myResultPropColl As ResultPropertyCollection
            myResultPropColl = mySearchResult.Properties
            Console.WriteLine("The properties of the 'mySearchResult' are :")
            Dim myKey As String
            For Each myKey In  myResultPropColl.PropertyNames
               Dim tab1 As String = "    "
               Console.WriteLine(myKey + " = ")
               Dim myCollection As Object
               For Each myCollection In  myResultPropColl(myKey)
                  Console.WriteLine(tab1 + myCollection)
               Next myCollection
            Next myKey
            myDirectoryEntry.Dispose()
            mySearchRoot.Dispose()
         Else
            Console.WriteLine("The '" + myLDAPPath + "' path not found.")
         End If
      Catch e As Exception
         Console.WriteLine("The '" + myLDAPPath + "' path not found.")
         Console.WriteLine("Exception : " & e.Message)
      End Try
   End Sub 'Main
End Class 'MySample
using System;
using System.DirectoryServices;

public class MySample
{
    public static void Main()
    {
        string myLDAPPath = "";
        try
        {
            // Create a 'DirectoryEntry' object to search.
            Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')");
            myLDAPPath = Console.ReadLine();

            DirectoryEntry mySearchRoot = new DirectoryEntry(myLDAPPath);
            DirectorySearcher myDirectorySearcher =
                    new DirectorySearcher(mySearchRoot);

            // Get the first entry of the search.
            SearchResult mySearchResult = myDirectorySearcher.FindOne();

            if ( mySearchResult != null )
            {
                // Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
                DirectoryEntry myDirectoryEntry =
                mySearchResult.GetDirectoryEntry();
                Console.WriteLine("\nThe name of the 'myDirectoryEntry' " +
                        "directory entry that corresponds to the " +
                        "'mySearchResult' search result is : {0}\n",
                        myDirectoryEntry.Name);
                string mySearchResultPath = mySearchResult.Path;
                Console.WriteLine("The path for the 'mySearchResult' search "
                        + "result is : {0}\n", mySearchResultPath);

                // Get the properties of the 'mySearchResult'.
                ResultPropertyCollection myResultPropColl;
                myResultPropColl = mySearchResult.Properties;
                Console.WriteLine("The properties of the " +
                        "'mySearchResult' are :");

                foreach( string myKey in myResultPropColl.PropertyNames)
                {
                    string tab = "    ";
                    Console.WriteLine(myKey + " = ");
                    foreach( Object myCollection in myResultPropColl[myKey])
                    {
                        Console.WriteLine(tab + myCollection);
                    }
                }
                mySearchRoot.Dispose();
                myDirectoryEntry.Dispose();
            }
            else
            {
                Console.WriteLine("The '" + myLDAPPath + "' path not found.");
            }
        }
        catch(Exception e)
        {
            Console.WriteLine("The '" + myLDAPPath + "' path not found.");
            Console.WriteLine("Exception : " + e.Message);
        }
    }

}

Kommentarer

Instanser av SearchResult klassen är mycket lika instanser av DirectoryEntry klassen. Den avgörande skillnaden är att klassen DirectoryEntry hämtar sin information från Doménové služby Active Directory-hierarkin varje gång ett nytt objekt används, medan data för SearchResult redan är tillgängliga i SearchResultCollection, där de returneras från en fråga som utförs med klassen DirectorySearcher. Endast de egenskaper som anges via DirectorySearcher.PropertiesToLoad samlingen i din fråga kommer att vara tillgängliga från SearchResult.

Egenskaper

Name Description
Path

Hämtar sökvägen för den här SearchResult.

Properties

Hämtar en ResultPropertyCollection samling egenskaper för det här objektet.

Metoder

Name Description
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetDirectoryEntry()

Hämtar DirectoryEntry som motsvarar SearchResult från Doménové služby Active Directory-hierarkin.

GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Gäller för