Skip to content

October 15, 2011

3

Hide “HOME” link in SharePoint 2010 Global Navigation

by Anders B. Skjønaa (SharePointPeople.dk)

The other day I was strugling to solve an issue that seemed pretty simple, but turned out not to be…

I needed to create a custom Global Navigation looking like this one:

Where the 3 icons linked to Home and to 2 different WebApps, and the rest of the navigation displayed second level sites (subsites) to the topsite.

To do this I created a custom CSS for the navigation and added a set of SPLinkButton’s to the left of the actual navigation control. The only thing I needed to change, was the behaviour of the navigation control, so that it would not display the “Home” link (links back to “/”). In other words, I needed the global navigation to only display links to subsites.

When looking at the control in the V4 masterpage, this is what you will see:

<asp:ContentPlaceHolder id=”PlaceHolderHorizontalNav” runat=”server”>
<SharePoint:AspMenu
ID=”TopNavigationMenuV4″
Runat=”server”
EnableViewState=”false”
DataSourceID=”topSiteMap”
AccessKey=”1″
UseSimpleRendering=”true”
UseSeparateCss=”false”
Orientation=”Horizontal”
StaticDisplayLevels=”2″
MaximumDynamicDisplayLevels=”1″
SkipLinkText=””
CssClass=”s4-tn”/>
<SharePoint:DelegateControl
runat=”server”
ControlId=”TopNavigationDataSource”
Id=”topNavigationDelegate”>
<Template_Controls>
<asp:SiteMapDataSource
ShowStartingNode=”False”
SiteMapProvider=”SPNavigationProvider”
id=”topSiteMap”
runat=”server”
StartingNodeUrl=”sid:1002″/>
</Template_Controls>
</SharePoint:DelegateControl>
</asp:ContentPlaceHolder>

The StartingNodeUrl property refers to a site with the SiteID og 1002. This is the topsite – first site on the 1st level. So I imagined that I could just set the ShowStartingNode property to “False” and I would be on my way. But no logic there – a least not my logic ;-)

So after trying a lot of different things out, I ended up by changing the SiteMapProvider and finally the menu started to change behaviour. My final solution also included removing the TopNavigationDataSource control, so the final code looks like this:

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

<asp:SiteMapDataSource
ShowStartingNode=”False”
SiteMapProvider=”CombinedNavSiteMapProvider”
id=”topSiteMap”
runat=”server”
StartingNodeUrl=”sid:1002″/>

Now documented for next time :-)

In the proces I used a small console program to display the Site ID’s. If you want tp try that out, here’s the C# for a simple console application to so that:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPNavigationNode toplinkbar = web.Navigation.GetNodeById(1002);
                    if (toplinkbar != null)
                    {
                        foreach (SPNavigationNode node in toplinkbar.Children)
                        {
                            Console.Write("SiteTitle: {0} ", node.Title);
                            Console.Write("SiteID: {0} ", node.Id);
                            Console.Write(System.Environment.NewLine);
                        }
                        Console.WriteLine("|");
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.ReadLine();
        }
    }
}

This will return a list of Subsites with Title and corresponding SiteID value. This example is a simple variation from MSDN, that can be a helpful tool when working with the sitestructure in SharePoint 2010.

3 Comments Post a comment
  1. Oct 21 2011

    good post!!
    zee

    http://walisystems.com

    Reply
  2. Chase
    Oct 12 2012

    Worked like a charm. Thanks!

    Reply

Trackbacks & Pingbacks

  1. Elegant D » Hide “HOME” link in SharePoint 2010 Global Navigation …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

Follow

Get every new post delivered to your Inbox.

Join 416 other followers