//First you should validate users (myppl is the people editor control id)
myppl.Validate();
if(myppl.IsValid)
{
// Get list (we will create new list item and add these people to one field of that list item)
SPList myList = SPContext.Current.Web.GetList("site/myListURL");
// Create list item
SPContentType itemtype = myList.ContentTypes["MyContentType"];
SPListItem newItem = myList.Items.Add();
newItem["ContentTypeId"] = itemtype.Id;
// This is where we shall gather all principals, to be added later to the list item
SPFieldUserValueCollection userPrincipals = new SPFieldUserValueCollection();
foreach (PickerEntity person in myppl.ResolvedEntities)
{
// Add everyone to the site with full permissions
SPPrincipal pr = mySPWeb.EnsureUser(person.Key) as SPPrincipal;
AddPrincipalRoleToSite(pr, SPRoleType.Administrator, myList.ParentWeb);
// Populate userPrincipals so we can use it below
SPUser usr = newItem.Web.EnsureUser(person.Key) as SPUser;
userPrincipals.Add(new SPFieldUserValue(newItem.Web, usr.ID, usr.Name));
}
// Finally set the value of the list item field that will contain all the users
newItem["PersonColumnInternalName"] = ownerPrincipals;
// All done, save item
newItem.Update();
}
public static void AddPrincipalRoleToSite(SPPrincipal entity, SPRoleType role, SPWeb web)
{
SPRoleAssignment roleAssignment = new SPRoleAssignment(entity);
SPRoleDefinition byType = web.RoleDefinitions.GetByType(role);
roleAssignment.RoleDefinitionBindings.Add(byType);
web.RoleAssignments.Add(roleAssignment);
}
You might be able to optimize the code within for loop (cast SPPrincipal into SPUser or something), I combined the code from few different projects of mine so it might not be 100% optimal.