Consistent Top Navigation Menu across All site collections in SharePoint 2010


Consistent Top Navigation Menu across All site collections in SharePoint 2010


Requirement: Display a consistent Top Navigation Menu across multiple site collections on the same web front ends in SharePoint.

We can fulfill this requirement by using custom sitemap providers in SharePoint. Here are the steps at high level
  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
Lets start building SharePoint 2010 common navigation across site collections.

1. 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\1033 directory is a great place since any site can get to that location (i.e. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\BPCorp.sitemap)

Create the sitemap as per the following template code

<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>
  </siteMapNode>
</siteMap>

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 : <siteMapNode title="EMEA" url="~/finance/EMEA/default.aspx">, use: ="~/finance/EMEA">. It also crashes when you have duplicate URLs in the siteMapNode!

2. Add a Site Map Provider in web.config file
Now that you have a site map you will need to add a provider in the web.config of the application that is going to use it. The providers section starts with <providers>. You will need to add a line similar to this.

< add name="BPCorpProvider" siteMapFile="_layouts/BPCorp.sitemap"
type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

3. Add a SiteMapDataSource to your master page
Next the master page needs to be changed. Edit the Master page you will be using with this site map in SharePoint Designer. You will need to add an asp:SiteMapDataSource right above the SharePoint:AspMenu like the one shown below.

< asp:SiteMapDataSource ShowStartingNode="False" SiteMapProvider="BPCorpProvider" id="BPCorpSiteMap" runat="server"/>

4. Reference the new data source in your Menu control
Next you will need to change DataSourceID field in the ASPMenu to match the ID of the SiteMapDataSource as shown below. Make sure you set value for MaximumDynamicDisplayLevels="3" , otherwise you won't get sub-menus!


<SharePoint:AspMenu ID="CustomNavigationMenu" Runat="server" EnableViewState="false" DataSourceID="BPCorpSiteMap" UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="1" MaximumDynamicDisplayLevels="2" SkipLinkText="<%$Resources:cms,masterpages_skiplinktext%>" CssClass="s4-tn">
<DataBindings>
<asp:MenuItemBinding DataMember="siteMapNode" TextField="title" NavigateUrlField="url" ValueField="title">
                </asp:MenuItemBinding>
</DataBindings>
</SharePoint:AspMenu>


Your code will look like this:
sharepoint 2010 consistent navigation across site collections
Save, check in, publish a major version, and approve your master page.

Please 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 &amp; for &, &lt; for <, and &gt; for >

Comments

  1. Hello Eric, thank you for your post. I am going to attempt this in my project. I am new to SharePoint so this may be a dumb question, but where is the location of the web.config that we add the "Site Map Provider" provider to? Do I have to modify the web.config for each site?

    ReplyDelete
    Replies
    1. c:\Inetpub\wwwroot\wss\VirtualDirectories\
      In my case I have 4 web applications so I have 4 folders in under VirtualDirectories.

      Delete

Post a Comment

Popular posts from this blog

SharePoint Designer 2013 Approval Workflow with Comments

Change SharePoint server hostname and Web Application Names

The Timer Service Failed to Recycle