<SharePoint:PeopleEditor ID="spPeoplePicker" runat="server" Width="350" SelectionSet="User" />
SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
SPWeb oSPWeb = oSPsite.OpenWeb();
SPList list = oSPWeb.Lists["PeopleList"];
oSPWeb.AllowUnsafeUpdates = true;
int iPeople = spPeoplePicker.ResolvedEntities.Count;
SPListItem itemToAdd = list.Items.Add();
for (int i = 0; i < iPeople; i++)
{
PickerEntity peEntity = spPeoplePicker.ResolvedEntities[i] as PickerEntity;
SPUser user = SPContext.Current.Web.EnsureUser(peEntity.Key);
itemToAdd["Title"] = "Test Title";
itemToAdd["User"] = user;
itemToAdd.Update();
}
To Clear the PeoplePicker
spPeoplePicker.Accounts.Clear();
spPeoplePicker.Entities.Clear();
SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
SPWeb oSPWeb = oSPsite.OpenWeb();
SPList list = oSPWeb.Lists["PeopleList"];
oSPWeb.AllowUnsafeUpdates = true;
int iPeople = spPeoplePicker.ResolvedEntities.Count;
SPListItem itemToAdd = list.Items.Add();
for (int i = 0; i < iPeople; i++)
{
PickerEntity peEntity = spPeoplePicker.ResolvedEntities[i] as PickerEntity;
SPUser user = SPContext.Current.Web.EnsureUser(peEntity.Key);
itemToAdd["Title"] = "Test Title";
itemToAdd["User"] = user;
itemToAdd.Update();
}
To Clear the PeoplePicker
spPeoplePicker.Accounts.Clear();
spPeoplePicker.Entities.Clear();
very Good Example its working for me
ReplyDelete