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

I have to write a utility to enumerate and manage the owners 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.

1 Answer

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; }
}
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like