3

I have a list Called Notification Groups which has a Person or Group field where multiple selection is allowed. Following is my code

SPList list = web.Lists["Notifications Group"];
                        foreach (SPListItem item in list.Items)
                        {
                            string fieldValue = item["Specific users"].ToString();
                            SPFieldUserValue userValue = new SPFieldUserValue(web, fieldValue);
                            string name = userValue.LookupValue;

                        }

But when i print the string name only the first user of each item gets printed without #id; rest all users of a particular item get printed with #id; any way of using SPFieldUserValue with Person or Group with multiple users selected? Anyone any ideas? Thanks in advance.

8
SPList list = web.Lists["Notifications Group"];
foreach (SPListItem item in list.Items)
{
    string fieldValue = item["Specific users"].ToString();
    SPFieldUserValueCollection users = new SPFieldUserValueCollection(web, fieldValue);

    foreach (SPFieldUserValue userValue in users)
    {
        SPUser user = userValue.User;
        //Do something with user
            int userId = user.ID;
            string userName = user.LoginName;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.