C#AD用户密码过期
我正在使用表格下面的代码,但我得到一个错误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'在目前情况下不存在
添加对System.DirectoryServices
.Net DLL的引用。
然后zaitsman的回答是:
using System.DirectoryServices.AccountManagement;
你有在cs文件中,该Passwordexpire方法存在的顶部using System.DirectoryServices.AccountManagement;
指令?
+1良好的体育精神,你刚才打我,但它只是解决方案 – 2013-03-09 08:45:15
THX一半的答复,在形式上采用荫和它不存在 – user113784 2013-03-09 08:48:47
杰里米·汤普森,是的,我种错过了参考一半,因为它对我来说更加明显,你不会访问你没有引用的东西,但我偶尔会发现自己在额外的类中输入类型,我忘记提及命名空间 – zaitsman 2013-03-09 08:52:33
Thx它的工作。名称'Dsearch'在当前上下文中不存在。你可以纠正代码 – user113784 2013-03-09 09:04:35