2
我需要遍歷網站集下的Web應用程序和子站點下的所有站點集合,並創建共享點下拉菜單。迭代所有SharePoint站點集合和子站點並創建鑽取菜單
我需要遍歷網站集下的Web應用程序和子站點下的所有站點集合,並創建共享點下拉菜單。迭代所有SharePoint站點集合和子站點並創建鑽取菜單
public class _starter : MasterPage
{
protected Menu CustomMenu;
protected void Page_Load(object sender, EventArgs e)
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
SPWebApplication webapp = site.WebApplication;
CustomMenu.Items.Clear();
BeginProcess(webapp);
}
}
public void BeginProcess(SPWebApplication webApp)
{
//Iterate through each site collection inside the web application
//Iterate through each site collection inside the site collection
foreach (SPSite site in webApp.Sites)
{
using (SPWeb oSPWeb = site.OpenWeb())
{
if (oSPWeb.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
{
MenuItem parentMenuItem = new MenuItem(oSPWeb.Title, oSPWeb.Title, "", oSPWeb.Url);
CustomMenu.Items.Add(parentMenuItem);
if (oSPWeb.Webs.Count > 0)
{
RecursiveWebCheck(oSPWeb, parentMenuItem);
}
}
}
}
}
private void RecursiveWebCheck(SPWeb parentoSPWeb, MenuItem parentMenuItem)
{
foreach (SPWeb web in parentoSPWeb.Webs)
{
MenuItem childMenuItem = new MenuItem(web.Title, web.Title, "", web.Url);
parentMenuItem.ChildItems.Add(childMenuItem);
RecursiveWebCheck(web, childMenuItem);
web.Dispose();
}
}
}