This documentation is archived and is not being maintained.

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)

[SecurityPermissionAttribute(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)]
[EnvironmentPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
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.


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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.