Ahmad Farid
Ahmad Farid

Reputation: 14764

How to get a list of all users in SharePoint

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

Upvotes: 7

Views: 17548

Answers (2)

Ahmad Farid
Ahmad Farid

Reputation: 14764

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/>"));
                }
            }

Upvotes: 7

Sachin
Sachin

Reputation: 876

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);
        }
    }
}

Upvotes: 11

Related Questions