How I simplified the Users and Group UI – Resolve the MembershipGroupID

So, one of the things I skipped over in my last post was just how you get the MembershipGroupID for the group you want the users to administer. Well, there are lots of options – all you’ve got to do is get to your page with the ListView with the correct value for the GET parameter MembershipGroupId.

If you knew the ID in advance, you could hard code it. I didn’t, so I used a redirect page. My page accepts a GET parameter of ‘OWNERS’, ‘VISITORS’, or ‘MEMBERS’ and redirects to the ‘list users’ page with the correct group ID. Again, I wrote this page in visual studio as code behind page to go in the _layouts directory.

protected void Page_Load(object sender, EventArgs e)
{
string group = Request.QueryString["group"];
SPWeb web = SPContext.Current.Web;
int igroup = web.AssociatedMemberGroup.ID;
if (group != null)
{
if (group.ToUpper() == "OWNERS")
{
igroup = web.AssociatedOwnerGroup.ID;
}
else if (group.ToUpper() == "VISITORS")
{
igroup = web.AssociatedVisitorGroup.ID;
}
}
SPUtility.Redirect("SimpleUG/ListUsers.aspx?MembershipGroupId=" + igroup, SPRedirectFlags.RelativeToLayoutsPage, this.Context);
}

That’s all there is too it – it get’s the ‘associated’ group for the web. You could do whatever you want here, though – look up specific groups by name, permission level, as specified elsewhere, whatever. I then built into the navigation of my site links to things like:

/_layouts/SimpleUG/UserAdmin.aspx?Group=OWNERS

which would resolve the ID of the Owners group, and forward the user to a list of the users in that group.

  • Introduction
  • How to Display a list of users
  • How to Find the MembershipGroupId
  • How to Add Users
  • How to Remove Users
  • Conclusion
  • Advertisement
    How I simplified the Users and Group UI – Resolve the MembershipGroupID

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s

    This site uses Akismet to reduce spam. Learn how your comment data is processed.