【问题标题】:Iterate all the sharepoint site collection and sub sites and create drill down menu迭代所有共享点网站集和子网站并创建向下钻取菜单
【发布时间】:2013-05-29 06:10:20
【问题描述】:

我需要遍历网站应用程序下的所有网站集和网站集下的子网站,并创建共享点向下钻取菜单。

【问题讨论】:

    标签: sharepoint-2010 sitecollection


    【解决方案1】:
    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();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多