Tuesday, July 30, 2013

Add data from People Picker control into people/Group column field of a list in Sharepoint Visual Webpart

The below code can be used in visual webpart where in you have a requirement to pick the data from people picker field and add the data to people or group column of any list


 SPFieldUserValueCollection customer = new SPFieldUserValueCollection();
                    foreach (PickerEntity enity in pepPickCustomer.ResolvedEntities)
                    {
                        SPUser user = SPContext.Current.Site.RootWeb.EnsureUser(enity.Key);
                       
customer .Add(new SPFieldUserValue(SPContext.Current.Site.RootWeb, user.ID, user.Name));

                    }

Later to add data to list

item["PeopleGroupColumName"] = customer;


*
pepPickCustomer is the ID of Client people picker control which is a new type of people picker control available Sharepoin 2013.

No comments:

Post a Comment