using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using System.Collections;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using System.Collections;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Drawing;
namespace AllUsersWebPart
{
[Guid("bb4dddf0-9923-43b9-a835-210735416ddf")]
public class AllUsers : System.Web.UI.WebControls.WebParts.WebPart
{
Label lblName;
Label lblgroups;
Table tblAllUsers;
{
[Guid("bb4dddf0-9923-43b9-a835-210735416ddf")]
public class AllUsers : System.Web.UI.WebControls.WebParts.WebPart
{
Label lblName;
Label lblgroups;
Table tblAllUsers;
public AllUsers()
{}
{}
protected override void CreateChildControls()
{
base.CreateChildControls();
{
base.CreateChildControls();
tblAllUsers = new Table();
lblgroups = new Label();
lblName = new Label();
lblgroups = new Label();
lblName = new Label();
CreateHeaderRow(); // Will Add a header Row to the Table.
using (SPSite SPSite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb SPWeb = SPSite.OpenWeb(SPContext.Current.Web.ID))
{
{
using (SPWeb SPWeb = SPSite.OpenWeb(SPContext.Current.Web.ID))
{
SPUserCollection AllSPWebUsers = SPContext.Current.Web.AllUsers;
SPGroupCollection AllSPWebGroups = SPContext.Current.Web.Groups;
//Iterate through each group in the current site.
foreach (SPGroup grp in AllSPWebGroups)
{
SPUserCollection UsersInGroup = grp.Users;
{
SPUserCollection UsersInGroup = grp.Users;
foreach (SPUser user in UsersInGroup)
{
lblName.Text = user.Name;
{
lblName.Text = user.Name;
foreach (SPGroup usergrp in user.Groups)
{
lblgroups.Text = usergrp.Name;
}
{
lblgroups.Text = usergrp.Name;
}
AddToTable(lblName.Text, lblgroups.Text);
}
}}}
}
}}}
this.Controls.Add(tblAllUsers);
}
// Adding users to the Output Table.
protected void AddToTable(string UserName, string grp)
{
TableRow r = new TableRow();
}
// Adding users to the Output Table.
protected void AddToTable(string UserName, string grp)
{
TableRow r = new TableRow();
TableCell CellName = new TableCell();
CellName.Text = UserName;
r.Cells.Add(CellName);
CellName.Text = UserName;
r.Cells.Add(CellName);
TableCell CellPermissions = new TableCell();
CellPermissions.Text = grp;
r.Cells.Add(CellPermissions);
CellPermissions.Text = grp;
r.Cells.Add(CellPermissions);
tblAllUsers.Rows.Add(r);
}
}
// Create a Header Row for the Output table.
protected void CreateHeaderRow()
{
protected void CreateHeaderRow()
{
TableHeaderRow headerRow = new TableHeaderRow();
headerRow.BackColor = System.Drawing.Color.LightBlue;
headerRow.BackColor = System.Drawing.Color.LightBlue;
TableHeaderCell headerTableCell1 = new TableHeaderCell();
TableHeaderCell headerTableCell2 = new TableHeaderCell();
headerTableCell1.Text = “User Name”;
headerTableCell1.Scope = TableHeaderScope.Column;
TableHeaderCell headerTableCell2 = new TableHeaderCell();
headerTableCell1.Text = “User Name”;
headerTableCell1.Scope = TableHeaderScope.Column;
headerTableCell2.Text = “Group”;
headerTableCell2.Scope = TableHeaderScope.Column;
headerTableCell2.Scope = TableHeaderScope.Column;
headerRow.Cells.Add(headerTableCell1);
headerRow.Cells.Add(headerTableCell2);
headerRow.Cells.Add(headerTableCell2);
tblAllUsers.Rows.AddAt(0, headerRow);
}
}}
}
}}
No comments:
Post a Comment