开发者

Get Current Navigation items for all site collections and webs - SP2010

开发者 https://www.devze.com 2023-02-11 09:41 出处:网络
I\'m trying to make a site map for a Sharepoint 2010 that will list every site and that site\'s current nav items. Navigation between sites is done via the top nav. However, I\'m having problems getti

I'm trying to make a site map for a Sharepoint 2010 that will list every site and that site's current nav items. Navigation between sites is done via the top nav. However, I'm having problems getting the current nav items for each site. It appears that each time I get the PortalSiteMapProvider for the web, it returns the provider for the whole site collection. How do I get the items for just that site? I run this code for each site I want to get the items for:

var provider = new PortalSiteMapProvider();
provider.NavigationType = PortalNavigationType.Current;
provider.CurrentWeb = web;
var rootNode = provider.RootNode;

Anyone have any idea w开发者_运维百科here to go from here?

EDIT: So it isn't possible to just access each site collection and run this code. The PortalSiteMapProvider doesn't allow it. It is, however, possible to run this code in a ashx that's located in the layouts folder. I just need to access that ashx file from the site collection I want to enumerate, and it will work just fine :)


    private void DrawWeb(SPWeb web, TreeNode node)
        {
            SPWebCollection webCol = web.Webs;
            foreach (SPWeb w in webCol)
            {
                var n = new TreeNode(w.Title);
                node.ChildNodes.Add(n);
                DrawWeb(w, n);
                w.Dispose();
            }
        }

Try calling this method like:

TreeNode webNode = new TreeNode(rootNode.Title);
DrawWeb(provider.CurrentWeb, webNode);

Hope this will be helpful.


So it isn't possible to just access each site collection and run this code. The PortalSiteMapProvider doesn't allow it. It is, however, possible to run this code in a ashx that's located in the layouts folder. I just need to access that ashx file from the site collection I want to enumerate, and it will work just fine :)

0

精彩评论

暂无评论...
验证码 换一张
取 消