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();
}
}