Sharepoint PeopleEditor: How do I know which type of user / group is returning?

I have PeopleEditor:

<SharePoint:PeopleEditor ID="peopleEdit" ... SelectionSet="User,DL,SecGroup,SPGroup" /> 

It works flawlessly on the page, that is, I can select AD users, Sharepoint groups and everything that I would like.

The problem is that I cannot find the property in PeopleEditor which type of user / group will be returned . 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 “hacker” things, for example, try to pass the value of the returned string [sic] as a user or as a group and execute some program flow based on an exception (if the user exists, otherwise, if the group exists, etc. .), but I would not consider this clean code.

Is there a better way to select people / groups in Sharepoint or a better way to work with PeopleEditor?

+6
c # sharepoint sharepoint-2010
source share
1 answer

Use the PrincipalType value from the EntityData hash table:

 string principalType = pickerEntity1.EntityData["PrincipalType"].ToString(); 

I do not remember all the possible values, but User and SharePointGroup definitely among them.


moontear comment:

To list all the information that this object has, an EntityDataElements array EntityDataElements useful. For SPGroup this contains SPGroupID , AccountName , PrincipalType .


Janis Weinbergs comment:

Maybe it contains values ​​from Microsoft.SharePoint.Utilities.SPPrincipalType enum, but I have not tested it.

Here you go:

 [Flags] public enum SPPrincipalType { None = , User = 1, DistributionList = 2, SecurityGroup = 4, SharePointGroup = 8, All = SharePointGroup | SecurityGroup | DistributionList | User, } 
+5
source share

All Articles