开发者

How do I use SPMemember.ID property to get User or Group

I have to write a utility to enumerate and manage the o开发者_开发知识库wners of groups within a SharePoint site. I know I can use the Groups property of the SPWeb object to retrieve a collection of groups. And I know I can use the Owner property of the group to get back the owner.

My problem is that I do not know what to do next. The SPGroup.Owner property returns a SPMember object. The member object has one property called ID that returns the unique ID (an integer) of the member. What I cannot seem to find information on is how to use that integer value to determine if the member is a User or a Group and how to get back additional details (say the name).

Any ideas?

Thanks.


You can try casting the SPMember to a specific type:- For example

using (SPWeb web = s.OpenWeb())
{
    SPGroup members = web.AssociatedMemberGroup;
    if (members.Owner is SPUser)
    {
        SPUser user = members.Owner as SPUser;
    }
    else if (members.Owner is SPGroup)
    {
        SPGroup group = members.Owner as SPGroup;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜