SharePoint User column and multiple values

 

Okay this is in a way update to my previous post about SharePoint lookup column.  This code example works well when you have column that is set to contain multiple user values.

 

(PeopleEditor pe; declared in the proper place and proper way)

ArrayList userLogins = pe.ResolvedEntities;

SPFieldUserValueCollection usersCollection = new SPFieldUserValueCollection();

foreach(PickerEntity userLogin in userLogins)

{

SPFieldUserValue valueToAdd = new SPFieldUserValue(SPContext.Current.Web, int.Parse(userLogin.EntityData[“SPUserID”].ToString()), userLogin.EntityData[“DisplayName”].ToString());

usersCollection.Add(valueToAdd);

}

//now we have a proper usersCollection with accounts that were given and validated in PeopleEditor

//and all what there is left is to save information as the SharePoint way which means userID;#DisplayName#;userID;# … which is quite painful if you try to make it only as a string modification

splistItem[“ColumnNameThatIsMultiUserColumn”] = usersCollection.ToString();

splistitem.Update();

 

Voilá a whole less painfull. I do not know if there is a way to get that SPFieldUserValueCollection directly from PeopleEditor, but for quick searching it seemed that things are not that simple. Feel free to comment if there is something more into this. And if needed I can create sample of adding these multiuservalues to PeopleEditor (which after creating this is more like walk in the park).

About Sakari H

I am software developer/architect from Finland. Originally I've worked long with SharePoint platform (from SharePoint 2007 to SharePoint 2019 & SharePoint Online), but now more with other things.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to SharePoint User column and multiple values

  1. Unknown says:

    thank you so much for this post it really helped me!!

  2. My brother recommended I may like this website. He was entirely
    right. This publish actually made my day.
    You can not imagine just how a lot time I had spent for this info!
    Thank you!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.