SPUser singleUser = new SPFieldUserValue(item.Web, item["Single User"] as string).User;
SPUser[] multipleUsers = ((SPFieldUserValueCollection)item["MultipleUsers"]).Cast<SPFieldUserValue>().Select(f => f.User);
I'm not sure why one user is stored as a string, but multiple users are stored as a specific object; it may also not be consistent in this so you might have to debug a bit and see what the type in your field is.
Once you have these SPUser
s, you can populate your PeopleEditor
control
using the account names as follows (quite long-winded):
ArrayList entityArrayList = new ArrayList();
foreach(SPUser user in multipleUsers) // or just once for a single user
{
PickerEntity entity = new PickerEntity;
entity.Key = user.LoginName;
entity = peMyPeople.ValidateEntity(entity);
entityArrayList.Add(entity);
}
peMyPeople.UpdateEntities(entityArrayList);
If you want to check any error messages that the control generates for you (if the user input is incorrect), you need to have done this switchout already:
var csa = usrBankSponsor.CommaSeparatedAccounts;
csa = usrOtherBankParties.CommaSeparatedAccounts;
//ErrorMessage is incorrect if you haven't done the above
if (!String.IsNullOrEmpty(usrBankSponsor.ErrorMessage))
{
...
}
OR
If you want to get the collection of users from PeopleEditor
than please try below code.
//get the collection of users from people editor
SPFieldUserValueCollection srvcRepCol = new SPFieldUserValueCollection();
int index = 0;
for (index = 0; index <= this.peopleEdControl.ResolvedEntities.Count - 1; ++index)
{
PickerEntity objEntity = (PickerEntity)this.peopleEdControl.ResolvedEntities[index];
srvcRepCol.Add(new SPFieldUserValue(srvcWeb, Convert.ToInt32(objEntity.EntityData["SPUserID"]), objEntity.Key));
}
//Assign the users to list item column
item["Customers"] = srvcRepCol;
//Set the value of users to people editor
if (item["Customers"] != null))
{
string users = string.Empty;
//To get the value from sharepoint list item and storing it in a SPFieldUserValueCollection.
SPFieldUserValueCollection userCol = new SPFieldUserValueCollection(web, item["Customers"].ToString());
foreach (SPFieldUserValue usrItm in userCol)
{
users += usrItm.User.ToString() + ",";
}
this.peopleEdControl.CommaSeparatedAccounts = users.Remove(users.LastIndexOf(","), 1);
}