【问题标题】:how to filter list items by user/group column in sharepoint?如何按共享点中的用户/组列过滤列表项?
【发布时间】:2010-11-26 20:15:16
【问题描述】:

我有一个列表,其中包含我想要过滤的用户/组列(列名是:USERS)。 如何在 USERS 列中仅获取当前用户所在的列表中的项目?

【问题讨论】:

  • 您的意思是通过 caml 查询还是通过自定义视图?

标签: list sharepoint filter


【解决方案1】:

如果它只是一个自定义视图,请查看任务列表和我的项目视图以供参考。

您应该能够转到视图中的“过滤器”部分,并拥有一个“等于”“[Me]”的过滤器。但是,这听起来像是一个多值字段,所以也许您可以使用“包含”“[Me]”。

如果您有 MOSS,另一个考虑因素是调查受众。内容查询 Web 部件能够根据受众过滤列表项。

【讨论】:

  • 我尝试创建一个视图并按“[Me]”过滤,但它只对用户有用,对组不利。我将用户和组混合在一起。
  • 我认为这是错误的。即使启用了多选,SharePoint 2007 也不会让您在 Person 或 Group 列上使用 contains 运算符。
【解决方案2】:
if (item["users"] != null)
{
    //get USERS field for item
    SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(web, item["users"].ToString());

    //go over the users/groups collection
    foreach (SPFieldUserValue fieldUserValue in fieldUserValueCollection)
    {
        if (fieldUserValue.User == null) //group
        {
            if (web.SiteGroups.GetByID(fieldUserValue.LookupId).ContainsCurrentUser)
            {
                bolItemGood = true;
                break;
            }
        }
        else //user
        {
            if (fieldUserValue.User.IsDomainGroup) //domain group
            {
                if (web.IsCurrentUserMemberOfGroup(fieldUserValue.LookupId))
                {
                    bolItemGood = true;
                    break;
                }
            }
            else //sp user
            {
                if (fieldUserValue.User.LoginName == Context.User.Identity.Name)
                {
                    bolItemGood = true;
                    break;
                }
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-07-19
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多