|
public static DirectoryEntry GetUser(string UserName)
{
//create an instance of the DirectoryEntry
DirectoryEntry de = GetDirectoryObject("/" + GetLDAPDomain());
//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher(de);
deSearch.SearchRoot =de;
//set the search filter
deSearch.Filter = "(&(objectCategory=user)(cn=" + UserName + "))";
//deSearch.SearchScope = SearchScope.Subtree;
//find the first instance
SearchResult results= deSearch.FindOne();
//if found then return, otherwise return Null
if(results !=null)
{
//de= new DirectoryEntry(results.Path,ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);
//if so then return the DirectoryEntry object
return results.GetDirectoryEntry();
}
else
{
return null;
}
}
|