我在表单中使用以下代码,但出现错误
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;
}
}
错误是:
找不到类型或命名空间名称 User Principal(是否缺少 using 指令或程序集引用?)
找不到类型或命名空间名称 Principal Searcher(是否缺少 using 指令或程序集引用?)
名称当前上下文中不存在“MatchType”