I have a PeopleEditor:
<SharePoint:PeopleEditor ID="peopleEdit" ... SelectionSet="User,DL,SecGroup,SPGroup" />
It works flawlessly on the page, i.e. I can select AD users, Sharepoint groups and anything I would like.
The problem is that I can't find a property on the PeopleEditor of what kind of user/group is returned. Let's take the following example:
//User: John Doe - mycompany\jondoe is at position 0
//Sharepoint group: "All Site Users" is at position 1
PickerEntity pickerEntity1 = (PickerEntity).peopleEdit.ResolvedEntities[1];
// pickerEntity1.Key = "All Site Users"
// pickerEntity1.Claim = null
// pickerEntity1.DisplayText = "All Site Users"
PickerEntity pickerEntity0 = (PickerEntity).peopleEdit.ResolvedEntities[0];
// pickerEntity1.Key = "mycompany\jondoe"
// pickerEntity1.Claim = null
// pickerEntity1.DisplayText = "Doe, John"
I can do some "hackish" things like trying to cast the returned string [sic] value as a User or as a Group and do some kind of Exception based program flow (if user exists do this, else if group exist etc.), but I wouldn't consider that clean code.
Is there a better method of choosing people/groups in Sharepoint or a better method to work with the PeopleEditor?
Use the PrincipalType
value from the EntityData
hashtable:
string principalType = pickerEntity1.EntityData["PrincipalType"].ToString();
I don't remember all possible values but User
and SharePointGroup
are definitely among them.
moontear's comment:
To list all information this entity has, the EntityDataElements
array is helpful. For SPGroup
this contains SPGroupID
, AccountName
, PrincipalType
.
Janis Veinbergs's comment:
It could be that it contains values from Microsoft.SharePoint.Utilities.SPPrincipalType
enum but i haven't tested it.
Here you go:
[Flags]
public enum SPPrincipalType
{
None = ,
User = 1,
DistributionList = 2,
SecurityGroup = 4,
SharePointGroup = 8,
All = SharePointGroup | SecurityGroup | DistributionList | User,
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With