Friday 4 November 2011

Customising SharePoint Global Navigation using Custom Sitemap

While working in SharePoint 2010 project I have found that custom global navigation doesn’t work consistently across the site collections. I have a custom master page which uses the custom navigation but the application pages never picked up my custom navigation.

In this blog I will explain how I created custom global navigation using custom sitemap, what are the issues I faced during development? How I tried to resolve those issues.

Steps to create custom xml SiteMapProvider:

  1. Create the custom xml sitemap which act as a data source for the site hierarchy say “CustomSiteMap.sitemap”.

  1. Add the following entry to your web.config(s) under the sitemap/providers node. This tells SharePoint who is the data provider for the custom data source created in Step 1.You can create a feature which will add the web.config modifications using SharePoint SPWebConfigModification class of SharePoint.
<add name=" TCContentContentMapProvider " siteMapFile="/_layouts/GlobalNavigation/CustomSiteMap.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />



  1. Next,  I have modified the master page and change the SharePoint:AspMenu  DataSourceID  from “topsitemap” to point to my custom TCContentContentMapProvider  whose id is “xmlSiteMap” as shown below.




Issues faces:

  1. From the root site if I select a link from the global navigation, It works however, once I land in the      selected site the global navigation stops navigating to any other links.
Example: From Home page I select the “About Me” link from the global navigation it lands me to About Me site. Now from “About Me” If I select “About You” or “Home” global navigation stops working to any of the links.

  1. Application/_layouts pages are not referring to my custom sitemap it is still referring to the “layout.sitemap” which is in 14 hive _layouts folder.

How did I resolve the Issues mentioned at the top:

Resolution for Issue 1:
Within the web.config file, update the custom provider line (you can find this by searching for the reference to your custom.sitemap file).  
Instead of using 
<add name=" TCContentContentMapProvider " siteMapFile="/_layouts/GlobalNavigation/CustomSiteMap.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

            Replace it with   
<add name=" TCContentContentMapProvider " siteMapFile="/_layouts/GlobalNavigation/CustomSiteMap.sitemap" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a " />

Resolution for Issue 2:
The magic trick to solve this issue is Delegate control in SharePoint.The purpose of this control is to allow developer to replace content with custom content by giving more priority using Sequence attribute. Hence I created delegate control feature to give my custom navigation more priority than SharePoint navigation and set the sequence less than 50 for publishing site.


Hope my blog is useful.

3 comments:

  1. Thanks it's getting me started on Site Map Providers.
    I've got to build one.

    Stephan Onisick
    sonisick@gmail.com

    ReplyDelete
  2. Could you please go into more detail on the delagate control. I'm not sure where to place the elements definition, and can't get the new menu system to work on the application pages. Thanks.

    ReplyDelete