GetDirectoryEntry Method
Collapse the table of content
Expand the table of content

SearchResult.GetDirectoryEntry Method ()

 

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

Namespace:   System.DirectoryServices
Assembly:  System.DirectoryServices (in System.DirectoryServices.dll)

[EnvironmentPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
[SecurityPermissionAttribute(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)]
public DirectoryEntry GetDirectoryEntry()

Return Value

Type: System.DirectoryServices.DirectoryEntry

The DirectoryEntry that corresponds to the SearchResult.

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.

System_CAPS_noteNote

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

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'.
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);

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft