Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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();
        }
       }
share|improve this question
    
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
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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