I am having a three site collection along with subsite in a same Web Application as below



We have the requirment to create a custom navigation provider and point all sitecollection in a single menu control and each will have similer global menu as below. We don't want to go for HardCoded/SiteMap file as in our requirement whenever any new subsite added in sitecollection should reflect at same time.

SiteCollection1 SiteCollection2 //on mouse hower subsite will display

I am using below code to generate the same but my function GetSiteMap not able to read sitecollection2 PortalSiteMapProvider value from sitecollection1. while I change the line childNodeB.ChildNodes = testchildNodeSiteB; with childNodeB.ChildNodes = nodeColl; it work fine and populate the value for current site.

enter code here

    public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode  node)
        string url1 = "http://dev:111";   //this is current site collection
        string url2 = "http://dev:111/sites/Sitecollection2";
        PortalSiteMapNode pNode = node as PortalSiteMapNode;
        if (pNode != null)
            if (pNode.Type == NodeTypes.Area)
                SiteMapNodeCollection nodeColl = base.GetChildNodes(pNode);
                                   SiteMapNodeCollection test = new SiteMapNodeCollection();

                SiteMapNode childNode2 = new SiteMapNode(this, url2, url2, "SiteCollection2");


                SiteMapNodeCollection testchildNodeSite2 = GetSiteMap(url2);
                ***childNode2.ChildNodes = testchildNodeSite2;***

                return nodeColl;
                return base.GetChildNodes(pNode);
            return new SiteMapNodeCollection();
    public SiteMapNodeCollection GetSiteMap(string url)
        //using (SPWeb oWeb = SPContext.Current.Site.OpenWeb(guidWebsite))

        using (SPWeb spweb = SPContext.Current.Site.AllWebs[url])//new SPSite(url))
            SPSite site = spweb.Site;

            SiteMapNodeCollection headingNodes = new SiteMapNodeCollection();
            headingNodes = null;

            PortalSiteMapProvider portalProvider = PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode;
            // Look up the node for the given Web site URL.
            PortalWebSiteMapNode webNode = portalProvider.FindSiteMapNode(url) as PortalWebSiteMapNode;

            if (webNode != null)
                headingNodes = portalProvider.GetChildNodes(webNode, NodeTypes.Heading, NodeTypes.None);

            return headingNodes;


Please suggest your views, how to read SiteMapNodeCollection of SiteCollection2 from SiteCollection1.


I had similar requirement long before.

You may find this helpful : How to get a reference of PortalSiteMapProvider object attached to a site that is not in current context

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.