Skip to content

Posts tagged ‘SharePoint Designer’

15
Oct

Hide “HOME” link in SharePoint 2010 Global Navigation

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.