从Web Applicaiton获取基于用户组的站点 [英] Get sites based on user groups from Web Applicaiton
问题描述
我在SharePoint Web应用程序中有大约5000个网站集。
我正在开发一个表单,我必须找到登录用户所属的网站所有者组(每个站点都有Owners组)并在网格中显示站点标题和URL。
请有人建议解决此要求。
pankaj
嗨Pankaj,
我们可以创建一个可视化的Web部件来实现它。以下代码供您参考。
VisualWebPart1UserControl.ascx
< asp:GridView ID =" GridView1" runat =" server">< / asp:GridView>VisualWebPart1UserControl.ascx.cs
使用Microsoft.SharePoint;
使用Microsoft.SharePoint.Administration;
使用System;
使用System.Data;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
命名空间VisualWebPartProject1.VisualWebPart1
{
public partial class VisualWebPart1UserControl:UserControl
{
protected void Page_Load(object sender,EventArgs e)
{
GridView1.DataSource = GetAllSiteCollections();
GridView1.DataBind();
}
protected DataTable GetAllSiteCollections()
{
DataTable dt = new DataTable();
dt.Columns.Add(" Site Title",typeof(string));
dt.Columns.Add(" URL",typeof(string));
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using(SPSite elevatedSite = new SPSite(SPContext.Current.Site.ID))
{
SPSiteCollection siteCollection = elevatedSite.WebApplication.Sites;
foreach(siteCollection中的SPSite站点)
{
using(SPWeb web = site.OpenWeb())
{
try
{
if(web.IsCurrentUserMemberOfGroup(web.Groups [web.Title +" Owners"。。ID))
{
DataRow dr = dt.NewRow();
dr [" Site Title"] = web.Title;
dr [" URL"] = web.Url;
dt.Rows.Add(dr);
}
} catch(例外e){
}
}
}
}
});
返回dt;
}
}
}
最好的问候,
Dennis
i have around 5000 site collections in a SharePoint Web application.
i am developing a form where i have to find the sites where logged in user belongs to Owners group(Each site has Owners group) and display the site title and URL in a grid.
Can someone suggest a solution for this requirement please.
pankaj
Hi Pankaj,
We can create a visual web part to achieve it. The following Code for your reference.
VisualWebPart1UserControl.ascx
<asp:GridView ID="GridView1" runat="server"></asp:GridView>VisualWebPart1UserControl.ascx.cs
using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System; using System.Data; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; namespace VisualWebPartProject1.VisualWebPart1 { public partial class VisualWebPart1UserControl : UserControl { protected void Page_Load(object sender, EventArgs e) { GridView1.DataSource = GetAllSiteCollections(); GridView1.DataBind(); } protected DataTable GetAllSiteCollections() { DataTable dt = new DataTable(); dt.Columns.Add("Site Title", typeof(string)); dt.Columns.Add("URL", typeof(string)); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite elevatedSite = new SPSite(SPContext.Current.Site.ID)) { SPSiteCollection siteCollection = elevatedSite.WebApplication.Sites; foreach (SPSite site in siteCollection) { using (SPWeb web = site.OpenWeb()) { try { if (web.IsCurrentUserMemberOfGroup(web.Groups[web.Title + " Owners"].ID)) { DataRow dr = dt.NewRow(); dr["Site Title"] = web.Title; dr["URL"] = web.Url; dt.Rows.Add(dr); } }catch(Exception e){ } } } } }); return dt; } } }Best Regards,
Dennis
这篇关于从Web Applicaiton获取基于用户组的站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!