8

我必须使用我的 AD 域中的所有人填充基于出色 ASPTokenInput 的类似自动完成 PeopleEditor 的控件反映 PeopleEditor 在他们的 Active Directory 搜索引擎中显示出真正的混乱,所有可能有用的类都是内部的。

我的测试方法工作正常,但我需要从 AD(不是共享点站点的)获取所有用户来填充我的列表: 它看起来如何

public string GetUsers(string filter)
    {
        var spWeb = SPContext.Current.Web;
        SPUserCollection allusers = spWeb.AllUsers;
        List<SPUser> users = allusers.Cast<SPUser>().ToList();
        var query = from spUser in users.Select(usr => new {id = usr.ID, name = usr.Name})
                        .Where(p => p.name.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    select new {id = spUser.id.ToString(), spUser.name};

        return new JavaScriptSerializer().Serialize(query);
    }

我怎样才能像这样查询活动目录?是否可以从 sharepoint 本身检索所有 AD 连接设置?我只需要 id 和用户名来填写我的下拉列表将其转换为 SPUserCollection 是另一件大事。

使用一些像这样的内置 SP 方法会很棒:

 [SubsetCallableExcludeMember(SubsetCallableExcludeMemberType.UnsupportedSPType)]
public static IList<SPPrincipalInfo> SearchWindowsPrincipals(SPWebApplication webApp, string input, SPPrincipalType scopes, int maxCount, out bool reachMaxCount)
4

2 回答 2

1

解决方案很简单,我唯一需要的是 SharePoint 组搜索实施(如果在字段编辑器控件中指定)。SP 有一个很好的内置方法,所以我使用它。

/// <summary>
/// Provides searching for AD or SharePoint group if specified in field setting
/// </summary>
public static class ActiveDirectorySearchProvider
{
    public static IList<SPPrincipalInfo> Search(string filter, string selectionGroup, string principalType)
    {
        var site = SPContext.Current.Site.WebApplication;
        bool reachmaxcount;
        var scope = SPUtils.GetSpPrincipalType(principalType);

        if (!String.IsNullOrEmpty(selectionGroup)) //search for users in SPGroup if present
        {
            var rawSPGroupList = SPUtility.GetPrincipalsInGroup(SPContext.Current.Web, selectionGroup, 100,
                                                           out reachmaxcount).ToList();

            string lowerFilter = filter.ToLowerInvariant();

            var filteredGroupList =
                rawSPGroupList.Where(
                    pInfo =>
                    pInfo.LoginName.Substring(pInfo.LoginName.IndexOf('\\') + 1).StartsWith(lowerFilter) ||
                    pInfo.DisplayName.ToLowerInvariant().StartsWith(lowerFilter) ||
                    pInfo.DisplayName.ToLowerInvariant().Substring(pInfo.DisplayName.IndexOf(' ') + 1).StartsWith(
                        lowerFilter)).ToList();

            return filteredGroupList;
        }

       return SPUtility.SearchWindowsPrincipals(site, filter, scope, 100, out reachmaxcount); //Search in AD instead

    }
于 2011-11-01T05:16:55.197 回答
0

我可以在这里想到两个选择。

  1. 您可以使用System.DirectoryServices并在您的 c# 代码中从您的 Active Directory 中查询所有用户。

  2. 您可以设置用户配置文件同步,以便您的 SharePoint 用户数据库是最新的。

于 2011-10-25T19:21:01.113 回答