Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取在active directory上创建的超过30天的用户-sharepoint c_C#_Visual Studio_Sharepoint - Fatal编程技术网

C# 获取在active directory上创建的超过30天的用户-sharepoint c

C# 获取在active directory上创建的超过30天的用户-sharepoint c,c#,visual-studio,sharepoint,C#,Visual Studio,Sharepoint,我有一个sharepoint 2013项目,我需要创建过去30天在active Directory上创建的所有员工的列表 最好的方法是什么 我想我可以使用system.DirectoryServices对active directory进行c查询,但因为我是在sharepoint场上实现的,我不知道这是否是最好的方法 在sharepoint上,我运行了用户配置文件服务,所以我的问题是,我是否可以使用用户配置文件服务或使用旧的c方式来实现这一点 谢谢 Flávio如果您运行用户配置文件服务同步服务

我有一个sharepoint 2013项目,我需要创建过去30天在active Directory上创建的所有员工的列表

最好的方法是什么

我想我可以使用system.DirectoryServices对active directory进行c查询,但因为我是在sharepoint场上实现的,我不知道这是否是最好的方法

在sharepoint上,我运行了用户配置文件服务,所以我的问题是,我是否可以使用用户配置文件服务或使用旧的c方式来实现这一点

谢谢
Flávio

如果您运行用户配置文件服务同步服务,您的用户信息列表将向上。然后可以按创建日期筛选列表。你也可以同步。包含用户信息列表的任何广告字段 简单:

用户信息列表已隐藏,因此键入

更多信息

ygy59关于隐藏用户信息列表是SharePoint中用户日期的唯一来源的说法是正确的。要以编程方式访问它,请执行以下操作:

using (ClientContext context = new ClientContext(projURL))
{
    CamlQuery query = new CamlQuery();
    query.ViewXml = "";
    ListItemCollection items = context.Web.SiteUserInfoList.GetItems(query);
    context.Load(items);
    context.ExecuteQuery();
    foreach (ListItem item in items)
    {
        DateTime hireDate = (DateTime)item["Created"];
        if(hireDate > DateTime.Today.AddDays(-30))
        {
            Console.WriteLine(item["Name"]);
        }
    }
    Console.ReadLine();
}
请务必注意,这是将项目添加到SharePoint的日期,而不是创建帐户的日期。这是你可以通过服务器设置来控制的

过去,当我为SharePoint环境创建这些类型的解决方案时,我经常需要对它们进行一次实时编辑,以考虑开始时未指定的新需求

我建议您设计您的解决方案,以便用户和/或您自己可以简单地添加要显示的额外字段,并按其他时间段进行选择,例如,过去7天的新用户,过去90天的新用户。或显示名字、登录名、姓氏、部门、经理、电子邮件、电话等

我们通过允许使用特定的URL参数来实现这一点,例如myreport.aspx?numdays=60&display=firstname、manager、email

祝你好运


Dorje

SharePoint的用户配置文件服务在很多方面都很有用,但我不确定它在这里是否有保证您不会创建访问群体、聚合来自多个来源的用户信息、公开可编辑属性等

假设这是一个内部部署的SharePoint场,再加上一个内部部署的Active Directory,我会直接访问Active Directory以获取此信息

如前所述,您需要在C代码中添加对System.DirectoryServices的引用

string subpath = "CN=something, CN=com"; // CNs appropriate to your environment here
string filter = ""; // append additional LDAP filter parameters as necessary

// build LDAP filter query
DateTime date = DateTime.UtcNow;
date.AddDays(-30);
string LDAPQuery = "(&(whenCreated>="+date.ToString("YYYYMMdd")+"000000.0Z)" + filter + ")";    

// get DNS host name
DirectoryEntry entry = new DirectoryEntry("LDAP://RootDSE");
Object value = entry.NativeObject;
string dnsHostName = entry.Properties["dnsHostName"].value.ToString();

// search Active Directory
DirectorySearcher searcher = new DirectorySearcher();
searcher.Filter = LDAPQuery;
searcher.SearchRoot = new DirectoryEntry("LDAP://"+dnsHostName+"/"+subpath);
SearchResultCollection results = searcher.FindAll();

// then iterate through results and 
// either display them on a page or create items in a list
正如Dorje McKinnon提到的,让代码足够灵活以适应新的需求是一个好主意。我将参数化LDAP查询和子路径字符串,并将它们放在某个SharePoint列表中,然后让您的C代码在执行查询之前从SharePoint列表中检索它们

如果此代码将频繁运行,并且仅用于报告目的,您可能希望避免为发现的每个广告配置文件创建SharePoint列表项,而只在页面上显示结果,例如在网格视图中