Hi Deb
I faced the same problem and this worked at my side:
public string GetCurrentUser(){
return System.Environment.UserName;
}
public static DirectoryEntry GetDirectoryEntry(){
string defaultNamingContext;
using(DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE")){
defaultNamingContext = "LDAP://" + root.Properties["defaultNamingContext"].Value;
}
DirectoryEntry entry = new DirectoryEntry(defaultNamingContext);
return entry;
}
public static DirectorySearcher GetDirectorySearcher(DirectoryEntry entry){
System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry);
return search;
}
// propertyName: SamAccountName, mail, streetAdress, cn
public string GetUserADProperties(string propertyName){
DirectoryEntry entry = GetDirectoryEntry();
DirectorySearcher search = GetDirectorySearcher(entry);
search.Filter = "(&(&(objectClass=user)(SamAccountName=" + GetCurrentUser() + ")))";
search.PropertiesToLoad.Add(propertyName);
SearchResult result = search.FindOne();
string propertyValue = "";
if(result != null){
propertyValue = result.Properties[propertyName][0].ToString();
}
return propertyValue;
}
hope it helps....