Click here to Skip to main content
13,558,432 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 9 Aug 2012
Licenced CPOL

SharePoint 2010 Groups and Users

, 17 Dec 2012
Rate this:
Please Sign up or sign in to vote.
The server object model for fetching groups and users.


In this article we can explore the Server Object Model for dealing with Groups and Users inside SharePoint.

Our Aim

Our aim is to create a webpart that displays the users and groups in a SharePoint site.

For example:

Group 1

  • User 1
  • User 2

Group 2

  • User 3
  • User 4

The Solution

Create a new SharePoint solution and add a new webpart into it. Place a Literal control over it.

Add using System.Text; 

In the Page Load event, add the following code: 

protected void Page_Load(object sender, EventArgs e)
    if (!this.Page.IsPostBack)

private void RefreshData()
    StringBuilder sb = new StringBuilder("<h2>Groups & Users</h2></br>");

    foreach (SPGroup group in SPContext.Current.Web.Groups)
        sb.Append("<b>Group: </b>" + group.Name + "</br>");
        foreach (SPUser user in group.Users)
            sb.Append(user.Name + "</br>");


    Literal1.Text = sb.ToString();

What the Code Does

SPContext.Current.Web.Groups returns all the groups for the particular web object. We can enumerate this using a foreach statement.

Group.Users returns the users inside the particular group. The object is represented by the SPUser object model.

Running the Code

On running the project, and adding the web part to the page, you can see the following results:

More Information on Groups and Users

I would like to add some related information from MSDN.


Gets the collection of user objects that represents all users who are either members of the site or who have browsed to the site as authenticated members of a domain group in the site.


Gets the collection of user objects that are explicitly assigned permissions in the Web site.


In this article we have explored the server object model for fetching groups and users. The web part displaying groups and users is attached with the article.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jean Paul V.A
United States United States
Jean Paul is a Microsoft MVP and Architect with 12+ years of experience. He is very much passionate in programming and his core skills are SharePoint, ASP.NET & C#.

In the academic side he do hold a BS in Computer Science & MBA. In the certification side he holds MCPD & MCTS spanning from .Net Fundamentals to SQL Server.

Most of the free time he will be doing technical activities like researching solutions, writing articles, resolving forum problems etc. He believes quality & satisfaction goes hand in hand.

You can find some of his work over here. He blogs at

You may also be interested in...


Comments and Discussions

QuestionThanks! and ... :-) Pin
renecschutte17-Dec-12 5:57
memberrenecschutte17-Dec-12 5:57 
GeneralMy vote of 5 Pin
renecschutte17-Dec-12 5:53
memberrenecschutte17-Dec-12 5:53 
GeneralRe: My vote of 5 Pin
Jean Paul V.A17-Dec-12 6:31
memberJean Paul V.A17-Dec-12 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180515.1 | Last Updated 17 Dec 2012
Article Copyright 2012 by Jean Paul V.A
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid