Wednesday, April 09, 2008

Create a simple sharepoint Webpart to see Groups and respective users

private StringBuilder Html;
private PeopleEditor p;
public SPWeb oWebsite;

protected override void Render(HtmlTextWriter writer)
{
try
{
oWebsite = SPContext.Current.Site.RootWeb;
SPGroupCollection collGroups = oWebsite.SiteGroups;
foreach (SPGroup oGroup in collGroups)
{
writer.Write(""+SPEncode.HtmlEncode(oGroup.Name) + "
");
foreach (SPUser users in oGroup.Users)
{
writer.Write(SPEncode.HtmlEncode(users.Name) + "
");
}
}
}
catch (Exception ex)
{
writer.Write(ex.Message + " " + ex.StackTrace);
}
}
Post a Comment