Skip to main content

Posts

Showing posts from August, 2007

Connecting to Active Directory - AD - using c#

Hi all, This is one of the most important and basic things a developer has to do in his life. Here I will show how to connect to the AD and get some basic information required. I also have covered fetching manager's information in this topic, I faced problem while working with this. When you search AD with UserID, it returns a path to the manager's information. We have to use the path and search the AD again to get manager's mailid and other information... public string GetManagerMailID(string UserName) { try { Hashtable hsEmpData; string sManagersMailID = ""; hsEmpData = SearchLDAP(UserName); foreach (DictionaryEntry deSearchDataKey in hsEmpData) { if (deSearchDataKey.Key.ToString() == "manager") { sManagersMailID = getManagersID(deSearchDataKey.Value.ToString()); break; } } return sManagersMailID; } catch (Exception ex) { throw ex; } } private static Hashtable SearchLDAP(string userID) { //Pass a connecetion string of sorts to the DirectoryEntry, //Her