About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, August 20, 2008

Active directory acces to get Telephone number

public Hashtable getUserTelephoneNumbers()
{
try
{
Hashtable arrNames = new Hashtable();
int count = 0;
string domain = "172.21.0.255";
DirectoryEntry de = new DirectoryEntry("LDAP://" + domain);
de.Username = "MS\\Administrator";
de.Password = "password";
DirectorySearcher ds = new DirectorySearcher(de);

ds.Filter = "(&(objectClass=user)(objectCategory=person))";

ds.Sort.Direction = System.DirectoryServices.SortDirection.Ascending; ds.SearchScope = SearchScope.Subtree;
ds.PageSize = 4000;
count++;

try
{
SortedList objSortedList = new SortedList();

foreach (SearchResult result in ds.FindAll())
{

DirectoryEntry deTemp = result.GetDirectoryEntry();

try

{

arrNames.Add(deTemp.Properties["cn"].Value.ToString(), deTemp.Properties["TelephoneNumber"].Value.ToString());

}

catch (Exception ex)
{
ex.Message.ToString();
}

}

}

catch (Exception ex)
{
//HttpContext.Current.Response.Write(ex.ToString());
}

finally
{
}
return arrNames;

}

catch
{
return null;

}

}

No comments:

My Masters