List All Groups and All users of site collection on a single page

Yes, you have been asked this question before haven’t you?

“Dear Admin, can you send me a complete list of all the users in the Visitors group of my site collection, because there are so many in them and I am not able to export to Excel……”

Well, I finally got sick of either copy/pasting the info from the People and Groups page or exporting all users using a powershell script, that I took the time to create my own aspx page that will display that directly.

the code for this page looks like this:

<%@ Assembly Name=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”%>
<%
@ Page Language=”C#” MasterPageFile=”~/_layouts/application.master” Inherits=”Microsoft.SharePoint.WebControls.LayoutsPageBase” %>
<%
@ Import Namespace=”Microsoft.SharePoint” %>

<
script runat=”server”>
   protected override void OnLoad(EventArgs e) {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
       
using (SPWeb thisWeb = this.Web)
        {
          
string output = “”;
           output +=
“<table style=\”width=100%\”>”;
           foreach (SPGroup group in thisWeb.Groups)
           {
              
output += “<tr><td colspan=\”3\”><strong>” + group.Name + “</strong><td></tr>”;
               int i = 0;
              
if (group.Users.Count > 0)
               {
                   
foreach (SPUser user in group.Users)
                    {
                          i++;
                          output +=
“<tr>”;
                          
output += “<td>” + user.Name + “</td>”;
                         
output += “<td>” + user.Email + “</td>”;
                         
output += “<td>” + user.LoginName + “</td>”;
                          output += “</tr>”;
                    }
              }
             
else
                  
output += “<tr><td colspan=\”3\”>Group is empty<td></tr>”;
              output +=
“<tr><td colspan=\”3\”>&nbsp;<td></tr>”;
         }
         output +=
“</table>”;
         lblUsers.Text = output;
      }
   }
);
}
</script>
<
asp:Content ID=”Main” runat=”server” contentplaceholderid=”PlaceHolderMain” >
<p>Site Groups and Users</p>
<asp:Label ID=”lblUsers” runat=”server” />
</asp:Content>
<
asp:Content ID=”PageTitle” runat=”server” contentplaceholderid=”PlaceHolderPageTitle” >
Site Groups and Users
</asp:Content>
<
asp:Content ID=”PageTitleInTitleArea” runat=”server” contentplaceholderid=”PlaceHolderPageTitleInTitleArea” >
Site Groups and Users
</asp:Content>

Now save this code into an aspx page and then copy that page to the 12-hive\TEMPLATE\Layouts folder. In my case I named the file Allusers.aspx, so now I f I am in a specific site collection, I can simply call upon the page using _layouts/allusers.aspx and have my listing of all the groups with all the users in a single page.

It is so simple, but never really had the time or desire to create such a page….

Stay tuned on my blog, as I  am almost ready with my tool for generating a complete report of a SharePoint farm in a nice html document….