Wednesday 5 August 2015

Read values from SharePoint people picker control in visual web part

Below is the code snippet to read values from SharePoint people picker control and update list item

 SPFieldUserValueCollection valueColl = new SPFieldUserValueCollection();

for (int i = 0; i < peoplePickerControlId.ResolvedEntities.Count; i++)
{
       PickerEntity peEntity = (PickerEntity)peoplePickerControlId.ResolvedEntities[i];
       SPUser user = SPContext.Current.Web.EnsureUser(peEntity.Key);
       SPFieldUserValue userVal = new SPFieldUserValue(web, user.ID, user.Name);
       valueColl.Add(userVal);
}

item["User"] = valueColl;

No comments:

Post a Comment