chloe
chloe

Reputation: 69

how to get the username of a SearchResultEntry

I am implementing the dirSync polling for changes within active directory, using ldap. It is working fine however i would like to get the username attribute ("samaccountname") associated with the SearchResultEntry object in addition to the changes that would be detected

Upvotes: 0

Views: 3381

Answers (2)

Jetti
Jetti

Reputation: 2458

SearchResult result; // this would've been defined elsewhere
if(result != null)
{
    DirectoryEntry entry = result.GetDirectoryEntry();
    string name = (string)entry["SAMAccountName"].Value;
}

This will allow you to get the name from the user and stores it in name and assumes you have a SearchResult named result already populated from some search on the directory.

Edit: I realized that this isn't what you asked for, you are using SearchResultEntry and not the DirectoryServices.SearchResult. I'll leave this here just in case it may help but I apologize for not properly reading the original question.

Upvotes: 1

Terry Gardner
Terry Gardner

Reputation: 11132

You must request the attributes as part of the search request. If the attribute(s) you desire are transmitted to the server as past of the search request, and if the server allows the authentication state of the connection to retrieve those attributes, then those attributes will be included in the search result. For more information, see LDAP: Programming Practices and Using ldapsearch. The latter refers to the command-line ldapsearch tool, but the concepts are valid for any language.

Upvotes: 1

Related Questions