传出员工号等信息,查询此人是否在AD中存在:
public bool ValidateEmpNoAndEmailId(string vEmpNo, string vEmailId)
{
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://ad.home.com");
DirectorySearcher srch = new DirectorySearcher(rootEntry);
srch.SearchScope = SearchScope.Subtree;
//搜寻条件....
srch.Filter = "(&(objectcategory=user)(sAMAccountName=" + vEmailId + "))";
SearchResultCollection res = srch.FindAll();
bool flag = res.Count <= 0 ? false : true;
srch.Filter = "(&(objectcategory=user)(company=" + vEmpNo + "))";
res = srch.FindAll();
flag = (flag == false) && res.Count <= 0 ? false : true;
return flag;
}