tags:

views:

238

answers:

2

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

+4  A: 
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);
        }
    }
}
Sachin
thanks man but i get this error."http://kermit:91/ExternalFAQ/default.aspx" contains illegal character ':'.what shall i write instead of the "Website_URL" ??
Ahmad Farid
A: 

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