Last post Mar 01, 2011 06:04 AM by itssabri
Jun 21, 2010 02:47 AM|itssabri|LINK
I want to retrieve employee's manager name from AD. For that I am using following code
de = GetDirectoryObject();
deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(&(objectClass=user)(cn=" + UserName + "*))";
deSearch.SearchScope = SearchScope.Subtree;
SearchResultCollection results = deSearch.FindAll();
foreach (SearchResult result in results)
DataRow dr = dt.NewRow();
DirectoryEntry dey = result.GetDirectoryEntry();
dr["Manager"] = dey.Properties["manager"].Value;
and I am getting the result as
so this is giving me a object which contains some properties (ou,cn,dc) and I want only the CN i.e. Saurabh
Jun 21, 2010 04:08 AM|ashiqf|LINK
Use the above code for obtaining the CN Alone, if needed you can also query AD to pull the first and last name.
Jun 21, 2010 06:53 AM|itssabri|LINK
thanks for reply ashiqf,
But it does not solve my problem...or may be I am not using it correctly..
Jun 21, 2010 10:03 AM|itssabri|LINK
what is the use PropertiesToLoad???
Jul 07, 2010 06:24 PM|smirnov|LINK
The manager attribute specifies the manager and its value is a distinguished name. You need to create a new query to LDAP to get the manager's object and obtain its properties. e.g.
string ldapPath = "LDAP://domain/" +"CN=Saurabh,OU=...";
DirectoryEntry de = new DirectoryEntry(ldapPath);
string cn = (string)de.Properties["name"].Value;
Hope this helps.
Dec 16, 2010 09:08 AM|ashiqf|LINK
Your code worked like a Charm. THanks but i am not able to mark this post as answer.
Dec 16, 2010 11:22 AM|smirnov|LINK
It does not answer your question and you need further help?
Mar 01, 2011 06:04 AM|itssabri|LINK
Sorry, got late to mark it as answer.