1

I have a site collection and a subsite underneath it. I have customized the top navigation based on business requirements, which out of box is not possible, by extending a class from PortalSiteMapProvider class. Everything works fine and i am able to see the navigation, which is derived from a list, on the top level site but when i navigate to subsite, it does not display.

Here is my master page settings

 <SharePoint:AspMenu  ID="TopNavigationMenuV4"  Runat="server"                     EnableViewState="false"
                              DataSourceID="topSiteMap"
                              AccessKey="<%$Resources:wss,navigation_accesskey%>"
                              UseSimpleRendering="true"
                              UseSeparateCss="false"
                              Orientation="Horizontal"
                              StaticDisplayLevels="1"
                              MaximumDynamicDisplayLevels="3"
                              SkipLinkText=""
                              CssClass="s4-tn"/>

                                <asp:SiteMapDataSource
                                              SiteMapProvider="MyNavigationProvider" 
                                              StartFromCurrentNode="true" 
                                              StartingNodeOffset="0" 
                                              ShowStartingNode="false" 
                                              EnableViewState="true"
                                              id="topSiteMap"
                                              runat="server"
                                          />
                                </asp:ContentPlaceHolder>

this is how i am creating a node

_psmn = new PortalSiteMapNode(
                                                        pPrtlWebSiteMapNode//WebNode
                                                        , _subitem.ID.ToString()//Key
                                                        , _ntypes//NodeTypes
                                                        , sUrl//URL
                                                        , _subitem.Title//Title
                                                        , sUrlDesc//Description
                                                     );

And this is my GetChildNodes method

        public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode pNode)
    {
     //The SiteMapNodeCollection which represents the children of this node
        SiteMapNodeCollection _children = new SiteMapNodeCollection();

        try
        {
            //If an absolute rootnode, then add the top level children which are the same for every site collection
            if (pNode == pNode.RootNode)
            {
                SPSite _rootSite = SPContext.Current.Site;
                SPWeb _rootWeb = _rootSite.RootWeb;

                //Serve it from cache if possible.

                object _topNodes = HttpRuntime.Cache["TopNavRootNodes"];


                lock (this)
                {

                    {
                        gRootNode = null;
                        LoadTopNavigationFromList();
                    }

                    //Else generate the top level nodes from memory. This must be done regardless of option 1 above
                    for (int i = 0; i < gTopLevelNodes.Count; i++)
                    {
                        _children.Add(gTopLevelNodes[i] as PortalSiteMapNode);
                    }

                    //Add them to the cache
                    HttpRuntime.Cache["TopNavRootNodes"] = _children;
                }
            }
            else
            //Else this is a subnode, get only the children of that subnode
            {
                string _nodeKey = pNode.Key;

                lock (this)
                {
                    {
                        gRootNode = null;
                        LoadTopNavigationFromList();
                    }

                    //Else iterate through the nodes and find the children of this node
                    for (int i = 0; i < gChildParentRelationship.Count; i++)
                    {
                        string _nKey = ((DictionaryEntry)gChildParentRelationship[i]).Key as string;

                        //if this is a child
                        if (_nodeKey == _nKey)
                        {
                            //Get the child from the arraylist
                            PortalSiteMapNode _child = (PortalSiteMapNode)(((DictionaryEntry)gChildParentRelationship[i]).Value);
                            if (_child != null)
                            {
                                _children.Add(_child as PortalSiteMapNode);
                            }
                            else
                            {
                                throw new Exception("ArrayLists not in sync.");
                            }
                        }
                    }

                    //Add the children to the cache
                    HttpRuntime.Cache["TopNavRootNodes" + _nodeKey] = _children;
                }
            }
        }
        catch (Exception ex)
        {
            //return empty site node collection
            return new SiteMapNodeCollection(); // No need to process
        }

        return _children;
}

Your Answer

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

Browse other questions tagged or ask your own question.