Indicate whether the user exist in AD
时间:2011-03-08 来源:流流
static bool IsExistInAD(UserInfo user)
{
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(SAMAccountName={0})", user.SAPID);
SearchResult result = search.FindOne();
if (result == null)
{
return false;
}
else
{
DirectoryEntry entry = result.GetDirectoryEntry();
//foreach (var temp in entry.Properties.PropertyNames)
//{
// Console.Write("" + temp.ToString() + ": " + entry.Properties[temp.ToString()][0] + Environment.NewLine);
//}
(entry.Properties["title"]).Value = user.Title;
(entry.Properties["company"]).Value = "Company";
(entry.Properties["telephoneNumber"]).Value ="+86 (21) "+ user.Tele;
(entry.Properties["mobile"]).Value = "+86 "+user.Mobile;
(entry.Properties["streetAddress"]).Value = "........";
(entry.Properties["postalCode"]).Value = "222221";
entry.CommitChanges();
Console.WriteLine(user.SAPID);
return true;
}
}