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
2009-08-12 14:38:59
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
2009-08-12 15:26:36
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
2009-08-12 15:39:45