Reputation: 21
I'm trying to query AD to retrieve user data.
Query works fine, but when enumerating through the properties returned via GetDirectoryEntry I am not able to see all the attributes I am seeing in Active Directory Explorer.
Code snippet below:
offEntry = pResult.GetDirectoryEntry();
foreach (PropertyValueCollection o in offEntry.Properties)
{
Debug.Print(o.PropertyName + " = " + o.Value.ToString());
}
I am seeing attributes like "displayName" and "SAMAccountName" etc, but not the attributes I really want, ex: "postalCode", "streetAddress".
I have tried searching for a solution for this specific problem but have come to a dead end. What am I missing???
Regards Peter
Upvotes: 2
Views: 3619
Reputation: 333
This is an old, but maybe it helps someone else:
Upvotes: 1
Reputation: 2078
You should be able to use a searcher class like this.
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(sAMAccountName=" + userAccount + ")";
search.PropertiesToLoad.Add("mail");
SearchResult result = search.FindOne();
then load the properties you want via the line
search.PropertiesToLoad.Add("mail");
then in your SearchResult
you will be able to read the properties
Upvotes: 1