SearchResult Class
The SearchResult class encapsulates a node in the Active Directory Domain Services hierarchy that is returned during a search through DirectorySearcher.
Assembly: System.DirectoryServices (in System.DirectoryServices.dll)
| Name | Description | |
|---|---|---|
![]() | Path | Gets the path for this SearchResult. |
![]() | Properties | Gets a ResultPropertyCollection collection of properties for this object. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetDirectoryEntry() | Retrieves the DirectoryEntry that corresponds to the SearchResult from the Active Directory Domain Services hierarchy. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
Instances of the SearchResult class are very similar to instances of DirectoryEntry class. The crucial difference is that the DirectoryEntry class retrieves its information from the Active Directory Domain Services hierarchy each time a new object is accessed, whereas the data for SearchResult is already available in the SearchResultCollection, where it gets returned from a query that is performed with the DirectorySearcher class. Only those properties that are specified through the DirectorySearcher.PropertiesToLoad collection in your query will be available from SearchResult.
The following example creates a new DirectoryEntry object with the desired path and uses the FindOne method to initiate the search. After performing the search, the example uses the GetDirectoryEntry method to retrieve the live directory entry identified in the search results.
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
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


