SearchResult 클래스

정의

SearchResult 클래스는 DirectorySearcher 통해 검색하는 동안 반환되는 Active Directory Domain Services 계층 구조의 노드를 캡슐화합니다.

public ref class SearchResult
public class SearchResult
type SearchResult = class
Public Class SearchResult
상속
SearchResult

예제

다음 예제에서는 원하는 경로 사용 하 여 새 DirectoryEntry 개체를 만들고 검색을 FindOne 시작 하는 메서드를 사용 합니다. 검색을 수행한 후 예제에서는 메서드를 GetDirectoryEntry 사용하여 검색 결과에서 식별된 라이브 디렉터리 항목을 검색합니다.

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

}

설명

클래스의 SearchResult 인스턴스는 클래스 인스턴스 DirectoryEntry 와 매우 유사합니다. 중요한 차이점은 DirectoryEntry 클래스는 새 개체에 액세스할 때마다 Active Directory Domain Services 계층 구조에서 해당 정보를 검색하는 반면 SearchResult 데이터는 SearchResultCollection 클래스로 수행된 쿼리에서 반환되는 DirectorySearcher 이미 사용할 수 있다는 것입니다. 쿼리의 컬렉션을 통해 DirectorySearcher.PropertiesToLoad 지정된 속성만 .에서 SearchResult사용할 수 있습니다.

속성

Name Description
Path

SearchResult경로의 경로를 가져옵니다.

Properties

이 개체의 ResultPropertyCollection 속성 컬렉션을 가져옵니다.

메서드

Name Description
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetDirectoryEntry()

Active Directory Domain Services 계층에서 DirectoryEntry 해당하는 SearchResult 검색합니다.

GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상