使用C#的Active Directory中的日期范围
问题描述:
我试图根据日期范围查找一些示例以从Active Directory中检索用户.
例如:如果我在Windows应用程序中输入2011年1月1日至2011年1月31日这样的日期.
我想检索在这些日期范围内创建的用户信息.
例如:用户Bob创建于2001年1月15日,那么我必须检索该用户名.
但不知道该搜索的搜索过滤器"是什么.
I was trying to find some example to retrieve user from Active Directory, based on Date Range.
For Eg: if i give a date like 1/01/2011 to 31/01/2011 in my windows application.
I wanna retrieve the user info , created on these date ranges.
For Eg: User Bob Created on 15/01/2001,then i have to retrieve that user name.
but am not sure what''s the "Search Filter" for that.
Any help appreciated
答
您能找到所有用户,然后使用IF语句显示在这些日期内创建的用户吗?
if(user.properties ["whenCreated"].value> StartDate && user.properties ["whenCreated"].value< EndData)
{
user.properties ["whenCreated"].value.ToString()
}
can you find all users and then use an IF statement to display the user created within these dates?
if(user.properties["whenCreated"].value > StartDate && user.properties["whenCreated"].value < EndData)
{
user.properties["whenCreated"].value.ToString()
}
逻辑性很好,您只需要调整我给出的示例以适合您的程序即可:
您将必须为startDate和endDate创建2个DateTime值.
因此在foreach循环中,您将看到如下所示的内容:
The logic is good, you just need to adapt the example i gave to fit your programme:
you''ll have to create 2 DateTime values for startDate and endDate.
so within the foreach loop you''ll have something that look like the below:
<pre lang="xml">DirectoryEntry user = new DirectoryEntry("LDAP://" + result.GetDirectoryEntry().Properties["distinguishedName"].Value.ToString());
if(user.Properties["whenCreated"].Value > startDate && user.Properties["whenCreated"].Value < endDate)
{
Console.WriteLine(user.Properties["cn"].Value.ToString() + " - " + user.Properties["whenCreated"].Value.ToString());
}