0

I want to add custom link to topnavigation bar, this link will be common through out sitecollections and it should appear as the first link in navigation bar. I have used following code to add my custom link but it is showing in second position of the top nav bar. Is there any way that i could appear at first position.

 public class MyCustomSiteMapProvider : PortalSiteMapProvider
{
    public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            PortalSiteMapNode pNode = node as PortalSiteMapNode;
            if (pNode != null)
            {
                string homeUrl = GetMyHomeUrl();
                if (pNode.Type == NodeTypes.Area && pNode.WebId == SPContext.Current.Site.RootWeb.ID)
                {
                    SiteMapNodeCollection nodeColl = base.GetChildNodes(pNode);
                    SiteMapNode homeNode = new SiteMapNode(this,
                                                            "<" + homeUrl + ">", "" + homeUrl + "",
                                                            "My Home");

                    nodeColl.Insert(0, homeNode);
                    base.CurrentNode.Title = "MY Home";

                    return nodeColl;
                }
                return base.GetChildNodes(pNode);
            }
            return new SiteMapNodeCollection();
        }
       }
  • Is the Publishing Infrastructure feature active on your site collection? In my experience, sites with the Publishing Infrastructure (site collection level) and Publishing (site level) features activated automatically add a navigation link (to the default page of the site) as the first link/node in the top navigation bar, and this link/node is inaccessible through code or through the Global Navigation group in AreaNavigationSettings. If anyone has an answer of how to access that node, I'd be interested to hear it. – Dylan Cristy Apr 9 '13 at 16:31
0

First get the SiteMapNodes from the collection, then call .Clear(), add yours first and then add the rest of them back.

Check this to see how they moved node items around: http://msdn.microsoft.com/en-us/library/system.web.sitemapnodecollection.item(v=vs.90).aspx

0

Why not use the OOTB Portal Site Connection setting? It will add your main site collection to the top of the bread crumb. See how to reactivate it here.

http://www.manageprojectsonsharepoint.com/blog/2012/12/19/restore-navigate-up-on-sharepoint-2013/

Otherwise, you may need to add that link manually to the first page in your sub-site collections. To that end, you could create a powershell script to do it. Hints on that here.

http://blog.blksthl.com/2012/02/12/site-settings-by-powershell-part-1-navigation/

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.