Showing posts with label WebControls. Show all posts
Showing posts with label WebControls. Show all posts

Friday, January 13, 2012

How to initialize PeopleEditor control?

You can use CommaSeparatedAccounts property for users. But this property doesn’t work for groups.

SPGroup
PeopleEditor peopleEditor = ...;
SPGroup group = ...;
PickerEntity entity = new PickerEntity
{
Key = group.LoginName,
DisplayText = group.Name,
Description = group.Name,
IsResolved = true
};
entity.EntityData.Add("AccountName", group.LoginName);
entity.EntityData.Add("SPGroupID", group.ID.ToString());
entity.EntityData.Add("PrincipalType", "SharePointGroup");
peopleEditor.Add(entity);


SPUser

PeopleEditor peopleEditor = ...;
SPUser user = ...;
PickerEntity entity = new PickerEntity
{
Key = user.LoginName,
DisplayText = user.Name,
Description = user.Name,
IsResolved = true
};
entity.EntityData.Add("AccountName", user.LoginName);
entity.EntityData.Add("SPUserID", user.ID.ToString());
if (user.IsDomainGroup)
entity.EntityData.Add("PrincipalType", "SecurityGroup");
else
entity.EntityData.Add("PrincipalType", "User");
peopleEditor.Add(entity);