How to filter list items by user / group column in sharepoint?

I have a list in which there is a user / group column that I want to filter (column name: USERS). How to get only those items in the list where the current user exists in the USERS column?

+3
source share
2 answers

If this is just a customized view, look at the to-do list and the My Positions view for reference.

You should be able to go to the "Filter" section in the view and have a filter that is "equal to" [Me] ". However, it looks like this is a multi-valued field, so you might be able to "contain" "[Me]".

, MOSS. - Content Query .

+1
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;
                }
            }
        }
    }
}
+1

Source: https://habr.com/ru/post/1717246/


All Articles