/ Published in: C#

Uses LDAP to find EMail address by using the sAMAccountName.
Add System.DirectoryServices to references.
Add System.DirectoryServices to references.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static string GetEmailBySAMAccountName(string sAMAccountName) { osearcher.Filter = string.Format("(&(sAMAccountName={0}))", sAMAccountName); var oresult = osearcher.FindAll(); if (oresult.Count == 0) throw new InvalidOperationException(string.Format("Cannot find sAMAccountName {0} in LDAP.", sAMAccountName)); if (oresult.Count > 1) throw new InvalidOperationException(string.Format("There are {0} items with sAMAccountName {1} in LDAP.", oresult.Count, sAMAccountName)); return oresult[0].Properties["mail"][0].ToString(); }
Comments
