I am using Sharepoint 2013. I have created a custom list. This custom list is using a custom contentype. In this custom contenttype I have a custom column. This column is a people picker. It is possible to select multiple users. In c# code I have created in vs an eventreceiver on itemupdating. I would like to add a new user to my people column. See code below how my code looks:

public override void ItemUpdating(SPItemEventProperties properties)

            var testManyUsers = properties.ListItem["TestManyUsers"];

            if (testManyUsers is SPFieldUserValueCollection)
                SPFieldUserValueCollection sPFieldUserValueCollection = (SPFieldUserValueCollection)testManyUsers;

                SPUser currentUser = SPContext.Current.Web.CurrentUser;

                sPFieldUserValueCollection.Add(new SPFieldUserValue(properties.Web, currentUser.ID, currentUser.Name));

                SPField spField = properties.ListItem.Fields["TestManyUsers"];
                properties.AfterProperties[spField.InternalName] = sPFieldUserValueCollection;


Ive got this error:

Invalid data has been used to update the list item. The field you are trying to update may be read only.


You need to disable the readonly property, enable AllowUnsafeUpdates, update the item and update the list:

myWeb.AllowUnsafeUpdates = true;

                    //Set the read only mode of people picker column to FALSE
                    currentitem.Fields["Betrokken specialisten"].ReadOnlyField = false;

SPFieldUserValueCollection sPFieldUserValueCollection = (SPFieldUserValueCollection)values;

                            SPUser currentUser = properties.Web.CurrentUser;

                            sPFieldUserValueCollection.Add(new SPFieldUserValue(properties.Web, currentUser.ID, currentUser.Name));

                            //Setting the property of people picker column
                            currentitem["Betrokken specialisten"] = sPFieldUserValueCollection;

                            //Update List Item
                            this.EventFiringEnabled = false;

                            //Update List

                            //Set the read only mode to TRUE
                            currentitem.Fields["Betrokken specialisten"].ReadOnlyField = true;

                            //Update the List item again

                            //update the List again

                            this.EventFiringEnabled = true;

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.