I am trying to get a user's email address in AD without success.
String account = userAccount.Replace(@"Domain\", "");
DirectoryEntry entry = new DirectoryEntry();
try {
DirectorySearcher search = new DirectorySearcher(entry);
search.PropertiesToLoad.Add("mail"); // e-mail addressead
SearchResult result = search.FindOne();
if (result != null) {
return result.Properties["mail"][0].ToString();
} else {
return "Unknown User";
}
} catch (Exception ex) {
return ex.Message;
}
Can anyone see the issue or point in the right direction?
"); Response.Write(result.Properties["sn"][0].ToString()); Response.Write("
"); Response.Write(result.Properties["mail"][0].ToString()); Response.Write("
"); Response.Write(FindName("gruberj")); – user95440 Apr 24 '09 at 14:22