I update sharepoint list by code. In list I have people picker field. It allows multi userand SharePoint group also. Before allowing multi user and group it was allowed only single user. So I used below code amd it was worked fine.

SPUser user = web.EnsureUser("ApproverField");
web.AllowUnsafeUpdates = true;

Now after changed to allow multi user and SharePoint group this code doesn't work. Exception fires at web.EnsureUser(). So can anyone suggest to make the change?


you can use the below function to store multiple users in People Picker

public SPFieldUserValueCollection GetSelectedUsers(PeopleEditor editor)
        string selectedUsers = editor.CommaSeparatedAccounts;
        char[] splitter = { ',' };
        string[] splitPPData = selectedUsers.Split(splitter);
        SPFieldUserValueCollection values = new SPFieldUserValueCollection();
        for (int i = 0; i < splitPPData.Length; i++)
            string loginName = splitPPData[i];
            if (!string.IsNullOrEmpty(loginName))
                SPUser user = SPContext.Current.Web.SiteUsers[loginName];
                SPFieldUserValue fuv = new SPFieldUserValue(SPContext.Current.Web, user.ID, user.LoginName);
                fuv = new SPFieldUserValue(SPContext.Current.Web, user.ID, user.LoginName);
                    return values;

Try following:

SPFieldUserValueCollection values = (SPFieldUserValueCollection)item["MultipleUsersField"];
values.Add(new SPFieldUserValue(web, user.ID, user.Name));
item["MultipleUsersField"] = values;


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.