Reputation: 897
I'm using DirectorySearcher.FindOne()
method.
I have specified Mobile
number in my Active Directory user properties. My search filter looks like this
(&(ObjectClass=User)(mobile=+11111111111))
With this filter I'm able to get appropriate user.
I've also specified Fax number in my AD user properties, but SearchResult
does not contain Fax property. In fact SearchResult
contain only one property, but I'm expecting all of user properties returned, including fax number.
Should I modify my query to get fax number returned? Maybe changes to my AD user or LDAP server required?
Upvotes: 2
Views: 8346
Reputation: 755227
When using DirectorySearcher
, you can define what properties will be included in SearchResult
by using the PropertiesToLoad
collection. If you don't specify anything, you only get the distinguished LDAP name
So try something like this:
DirectoryEntry root = new DirectoryEntry("LDAP://-your-base-LDAP-path-here-");
DirectorySearcher searcher = new DirectorySearcher(root);
searcher.Filter = "(&(ObjectClass=User)(mobile=+11111111111))";
// DEFINE what properties you need !
searcher.PropertiesToLoad.Add("Mobile");
searcher.PropertiesToLoad.Add("Fax");
SearchResult result = searcher.FindOne();
if (result != null)
{
if (result.Properties["Fax"] != null)
{
string fax = result.Properties["Fax"][0].ToString();
}
if (result.Properties["Mobile"] != null)
{
string mobile = result.Properties["Mobile"][0].ToString();
}
}
Upvotes: 5