Consistent Top Navigation For All Site Collections In SharePoint 2010/2013

Rohit Dixit Novice (N)

Posted on: Tue, 20 Jun 2017, Views : #4905

Topics : Sharepoint / WSS,


 Applies To: SharePoint 2010 & SharePoint 2013

 

How to Display a consistent Top Navigation Menu for across site collections in SharePoint 2010/2013.

 

We can achieve this by using custom sitemap providers in SharePoint by following below given steps:

  1. Create your own sitemap file in Layouts folder
  2. Add a Site Map Provider in web.config file
  3. Add a SiteMapDataSource to your master page
  4. Change the SharePoint menu's datasource to your custom SiteMapDataSource

 

Below here the detailed description of each steps being used in this process with example.

Create your own sitemap file in Layouts folder:

Modify the site map to match your navigation needs and save it with a ".sitemap" extension in a location accessible by your SharePoint farm. The _LAYOUTS directory is a great place since any site can get to that location (i.e. _/layouts/BPCorp.sitemap)

Create the sitemap as per the following template code

----------------------------------------------------------- Code Starts -----------------------------------------------------------

 

<sitemap>

    <siteMapNode title="Container" url=""/>

    <siteMapNode title="Global Portal" description="" url="/" />

     <siteMapNode title="Finance" description="" url="~/finance" >

             <siteMapNode title="EMEA" url="~/finance/EMEA" description="" />

             <siteMapNode title="APAC" url="~/finance/APAC" description="" />

             <siteMapNode title="CORP" url="~/finance/CORP" description="" />

    </siteMapNode>

      <siteMapNode title="Team" description="" url="~/team" />

    <siteMapNode title="Information Technology" description="" url="~/it" />

    <siteMapNode title="Legal" description="" url="~/legal" />

    <siteMapNode title="Regions" description="" url="" >

           <siteMapNode title="North America" url="~/regions/NA" description=""/>

                <siteMapNode title="Middle East" url="~/regions/me" description=""/>

   </siteMapNode>

</sitemap>

 ----------------------------------------------------------- Code Ends-----------------------------------------------------------

 

Note: Site Map control crashes with error "An unexpected error has occurred." when you point to a page in the URL (instead of Site) and that site is with broken permissions. Fix is simple: Instead of : , use: ="~/finance/EMEA">. It also crashes when you have duplicate URLs in the siteMapNode!

  

Add a Site Map Provider in web.config file:

Now that the site map is ready we need to add a provider in the web.config of the application that is going to use it. The providers section starts with . You will need to add a line similar to this.

     type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

 

Add a SiteMapDataSource to your master page:

To add SiteMapDataSource, you need to Edit the Master page you will be using with this site map in SharePoint Designer and add an asp:SiteMapDataSource right above the SharePoint:AspMenu like the one shown below in step 4.

  

Change the SharePoint menu's datasource to your custom SiteMapDataSource:

We need to change DataSourceID field in the ASPMenu to match the ID of the SiteMapDataSource as shown below and Make sure to set value for MaximumDynamicDisplayLevels="3" , otherwise we won't get sub-menus!

 

----------------------------------------------------------- Code Starts -----------------------------------------------------------

 <SharePoint:AspMenu

       ID="TopNavigationMenuV4"

       Runat="server"

       EnableViewState="false"

       DataSourceID="BPCorpSiteMap"

       AccessKey="<%$Resources:wss,navigation_accesskey%>"

       UseSimpleRendering="true"

       UseSeparateCss="false"

       Orientation="Horizontal"

       StaticDisplayLevels="1"

       MaximumDynamicDisplayLevels="3"  

       SkipLinkText=""

      CssClass="s4-tn"/>

 ----------------------------------------------------------- Code Ends-----------------------------------------------------------

Your code should look like this:

 


Save, check in, publish a major version, and approve your master page.

Note: XML is case sensitive, and you got to replace any special codes like %20 (space) with the literal (i.e. a space). Also there are some special characters for XML like & for &, < for <, and > for >
​


Finally, Here is what you will get:

 

 

 

 

Drop your feedback

Login Now Sign up



Note : You are required to be logged-in as a user to leave a feedback.