使用C#的Active Directory中的日期范围 [英] Date Range in Active Directory using C#

查看:72
本文介绍了使用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());
               }



这篇关于使用C#的Active Directory中的日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆