.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Groups and Users in SharePoint 2010

Posted By:Jean Paul       Posted Date: April 30, 2013    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

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

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 & groups in the 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.

In the Page Load event add the following code 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 SPUser object model.

Running the Code

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

More Information on Groups & 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 & users.  The web part displaying groups & users is attached with the article.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend