using System.DirectoryServices;
using ActiveDs;
try
{
// ActiveDirectoryのIPアドレス:192.168.1.100
// ドメイン:pr.local
string adPath = "LDAP://192.168.1.100/DC=pr,DC=local";
DirectoryEntry de = new DirectoryEntry(adPath);
DirectorySearcher schr = new DirectorySearcher(de);
schr.SizeLimit = 2147483647;
schr.PageSize = 1000;
schr.Filter = String.Format("(&(objectClass=user)(samAccountName={0}))", strUserName);
SearchResult sr = schr.FindOne();
if (sr == null)
{
throw new System.ArgumentException("Not found user " + strUserName + " using Active Directory.", "original");
}
DirectoryEntry userEntry = sr.GetDirectoryEntry();
string strMail = (string)userEntry.Properties["mail"].Value;
if (strMail == "")
{
throw new ArgumentException("Nothing Mail Address to " + strUserName, "original");
}
return strMail;
}
catch (ArgumentException ex)
{
throw ex;
}
最近のコメント