Sharepoint PeopleEditor:如何找出返回的用户/组类型? [英] Sharepoint PeopleEditor: How to find out what kind of user/group is returned?
问题描述
我有一个 PeopleEditor:
I have a PeopleEditor:
<SharePoint:PeopleEditor ID="peopleEdit" ... SelectionSet="User,DL,SecGroup,SPGroup" />
它在页面上完美运行,即我可以选择 AD 用户、Sharepoint 组和任何我想要的.
It works flawlessly on the page, i.e. I can select AD users, Sharepoint groups and anything I would like.
问题是我在 PeopleEditor 上找不到返回什么样的用户/组的属性.我们来看下面的例子:
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"
我可以做一些hackish"的事情,比如尝试将返回的字符串 [sic] 值转换为用户或组,并执行某种基于异常的程序流(如果用户存在,则执行此操作,否则如果组存在等.),但我不会考虑干净的代码.
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.
是否有更好的方法在 Sharepoint 中选择人员/组或使用 PeopleEditor 的更好方法?
推荐答案
使用 EntityData
哈希表中的 PrincipalType
值:
Use the PrincipalType
value from the EntityData
hashtable:
string principalType = pickerEntity1.EntityData["PrincipalType"].ToString();
我不记得所有可能的值,但 User
和 SharePointGroup
肯定在其中.
I don't remember all possible values but User
and SharePointGroup
are definitely among them.
moontear的评论:
要列出该实体的所有信息,EntityDataElements
数组很有帮助.对于 SPGroup
,它包含 SPGroupID
、AccountName
、PrincipalType
.
To list all information this entity has, the EntityDataElements
array is helpful. For SPGroup
this contains SPGroupID
, AccountName
, PrincipalType
.
Janis Veinbergs 的评论:
可能是它包含来自 Microsoft.SharePoint.Utilities.SPPrincipalType
枚举的值,但我还没有测试过.
It could be that it contains values from Microsoft.SharePoint.Utilities.SPPrincipalType
enum but i haven't tested it.
给你:
[Flags]
public enum SPPrincipalType
{
None = ,
User = 1,
DistributionList = 2,
SecurityGroup = 4,
SharePointGroup = 8,
All = SharePointGroup | SecurityGroup | DistributionList | User,
}
这篇关于Sharepoint PeopleEditor:如何找出返回的用户/组类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!