tags:

views:

75

answers:

1

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  A: 

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

}

Paul Lucas
Awesome. Did not even think to try casting it. Was expecting some sort of API call. Thanks Paul.
Jason
As a followup question, let's say all I had was the integer value of the ID. Is there an API call that allows me to instantiate a SPUser or SPGroup object with just the ID value?
Jason
The only way I know is to test for both ie web.AllUsers.GetByID(id);web.Groups.GetByID(id); if the id is not a user, AllUsers.GetById will throw an exception and vice versa for a group.
Paul Lucas
Ugly but that works for me. Thanks again.
Jason