我正在使用表格下面的代碼,但我得到一個錯誤C#AD用戶密碼過期
public DataTable Passwordexpire()
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal userTemplate = new UserPrincipal(ctx);
userTemplate.AdvancedSearchFilter.AccountExpirationDate(DateTime.Today.AddDays(3), MatchType.LessThanOrEquals);
PrincipalSearcher searcher = new PrincipalSearcher(userTemplate);
foreach (Principal foundPrincipal in searcher.FindAll())
{
UserPrincipal foundUser = (foundPrincipal as UserPrincipal);
if (foundUser != null)
{
DataTable dt = new DataTable();
dt.Columns.Add("AccountName");
dt.Columns.Add("Name");
dt.Columns.Add("Empolyee ID");
dt.Columns.Add("Company");
foreach (SearchResult sResultSet in Dsearch.FindAll())
{
DataRow dr = dt.NewRow();
dr[0] = (GetProperty(sResultSet, "samaccountname"));
dr[1] = (GetProperty(sResultSet, "name"));
dr[2] = (GetProperty(sResultSet, "ExtensionAttribute2"));
dr[3] = (GetProperty(sResultSet, "Company"));
dt.Rows.Add(dr);
}
return dt;
}
}
的錯誤是:
類型或命名空間名稱的用戶主體找不到( )
無法找到類型或名稱空間名稱Principal Searcher(您是否缺少使用指令或程序集引用?)
名稱'MatchType'在目前情況下不存在
Thx它的工作。名稱'Dsearch'在當前上下文中不存在。你可以糾正代碼 – user113784 2013-03-09 09:04:35