This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String GetUserEmail(string UserName) | |
{ | |
try | |
{ | |
string strpath = _LdapPath; | |
DirectoryEntry ou = new DirectoryEntry(strpath, _AdminUserName, _AdminPassword); | |
DirectorySearcher ds = new DirectorySearcher(ou); | |
String[] strArray = UserName.Split('\\'); | |
if (strArray.Length > 1) | |
UserName = strArray[1]; | |
string filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "User", UserName); | |
ds.Filter = filter; | |
SearchResult result = ds.FindOne(); | |
DirectoryEntry directoryEntry = result.GetDirectoryEntry(); | |
if (directoryEntry.Properties["mail"] != null) | |
return Convert.ToString(directoryEntry.Properties["mail"].Value); | |
return ""; | |
} | |
catch (Exception ex) | |
{ | |
LogErrors(ex, "GetUserEmail"); | |
return null; | |
} | |
} |