.NET Framework Class Library  

SearchResult.GetDirectoryEntry Method

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

[Visual Basic]
Public Function GetDirectoryEntry() As DirectoryEntry
[C#]
public DirectoryEntry GetDirectoryEntry();
[C++]
public: DirectoryEntry* GetDirectoryEntry();
[JScript]
public function GetDirectoryEntry() : DirectoryEntry;

Return Value

The DirectoryEntry that corresponds to the SearchResult.

Remarks

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

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

Example

[Visual Basic, C#, C++] The following example is an excerpt of the example in SearchResult. The original example creates a new DirectoryEntry with the search criteria and uses the FindOne method to initiate the search. The search result is stored in GetDirectoryEntry.

[Visual Basic, C#, C++] This example shows how to retrieve and parse the search result from GetDirectoryEntry.

[Visual Basic] 
' 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)

[C#] 
// 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);

[C++] 
// Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
DirectoryEntry* myDirectoryEntry = mySearchResult->GetDirectoryEntry();
Console::WriteLine(
    String::Concat(S"\nThe name of the 'myDirectoryEntry' ",
    S"directory entry that corresponds to the ",
    S"'mySearchResult' search result is : {0}\n"),
    myDirectoryEntry->Name);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

SearchResult Class | SearchResult Members | System.DirectoryServices Namespace | DirectorySearcher