Below is the code snippet to read users from User and group field and assigning the same to the people picker control in form
SPFieldUserValueCollection trainerColl = new SPFieldUserValueCollection(web, Convert.ToString(ItemColl[0]["User"]));
List<PickerEntity> trainersEntity = new List<PickerEntity>();
foreach (SPFieldUserValue spuserval in trainerColl)
{
SPUser userToassign = spuserval.User;
PickerEntity entity = new PickerEntity();
PeopleEditor pe = new PeopleEditor();
entity.EntityData["Account Name"] = spuserval.User.LoginName;
entity.EntityData["SPUserId"] = spuserval.User.ID;
entity.EntityDa"Email"] = spuserval.User.Email;
entity.Key = spuserval.User.LoginName;
entity.Description = spuserval.User.LoginName;
entity.DisplayText = spuserval.User.Name;
entity = pe.ValidateEntity(entity);
entity.IsResolved = true;
peoplepickerControlId.Entities.Add(entity);
}
SPFieldUserValueCollection trainerColl = new SPFieldUserValueCollection(web, Convert.ToString(ItemColl[0]["User"]));
List<PickerEntity> trainersEntity = new List<PickerEntity>();
foreach (SPFieldUserValue spuserval in trainerColl)
{
SPUser userToassign = spuserval.User;
PickerEntity entity = new PickerEntity();
PeopleEditor pe = new PeopleEditor();
entity.EntityData["Account Name"] = spuserval.User.LoginName;
entity.EntityData["SPUserId"] = spuserval.User.ID;
entity.EntityDa"Email"] = spuserval.User.Email;
entity.Key = spuserval.User.LoginName;
entity.Description = spuserval.User.LoginName;
entity.DisplayText = spuserval.User.Name;
entity = pe.ValidateEntity(entity);
entity.IsResolved = true;
peoplepickerControlId.Entities.Add(entity);
}
No comments:
Post a Comment