SearchResult.GetDirectoryEntry SearchResult.GetDirectoryEntry SearchResult.GetDirectoryEntry SearchResult.GetDirectoryEntry Method


Retrieves the DirectoryEntry that corresponds to the SearchResult from the Active Directory Domain Services hierarchy.

 System::DirectoryServices::DirectoryEntry ^ GetDirectoryEntry();
public System.DirectoryServices.DirectoryEntry GetDirectoryEntry ();
member this.GetDirectoryEntry : unit -> System.DirectoryServices.DirectoryEntry
Public Function GetDirectoryEntry () As DirectoryEntry



The following example is an excerpt of the example in SearchResult. The original 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 that is identified in the search results.

' 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)  
// Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.  
DirectoryEntry myDirectoryEntry =   
Console.WriteLine("\nThe name of the 'myDirectoryEntry' " +  
                  "directory entry that corresponds to the " +  
                  "'mySearchResult' search result is : {0}\n",  
// Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.  
DirectoryEntry^ myDirectoryEntry = mySearchResult->GetDirectoryEntry();  
    String::Concat("\nThe name of the 'myDirectoryEntry' ",  
    "directory entry that corresponds to the ",  
    "'mySearchResult' search result is : {0}\n"),  


Use GetDirectoryEntry when you want to look at the live entry instead of the entry that was returned through DirectorySearcher, or when you want to invoke a method on the object that was returned.


Calling GetDirectoryEntry on each SearchResult returned through DirectorySearcher can be slow.

Applies to