How to get a list of all users in SharePoint

How to get a list of all users in a specific group in SharePoint by code?

+6
c # sharepoint
source share
2 answers

I used this first line instead, and it worked. thanks dude:)

SPGroupCollection collGroups = SPContext.Current.Web.Groups; foreach (SPGroup oGroup in collGroups) { foreach (SPUser oUser in oGroup.Users) { Response.Write(oUser.Name); Label l = new Label(); l.Text = oUser.Name; PlaceHolderContents.Controls.Add(l); PlaceHolderContents.Controls.Add(new LiteralControl("<br/>")); } } 
+6
source share
 using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL")) { SPGroupCollection collGroups = oWebsite.Groups; foreach (SPGroup oGroup in collGroups) { foreach(SPUser oUser in oGroup.Users) { Response.Write(oUser.Name); } } } 
+11
source share

All Articles