Tuesday, September 2, 2008

Implementing TopNavigation across site collection

You can use Microsoft.SharePoint.Navigation.SPXmlContentMapProvider.

  • Add the following tag to your web.config under the sitemap/providers node.
    <add name="CustomXmlContentMapProvider" siteMapFile="_app_bin/myMenu.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

  • In the same website, add a myMenu.sitemap file with the following contents -

<siteMap>
<siteMapNode title="Home Page" url="/">
<siteMapNode title="Lists" url="http://Mysite/_layouts/viewlsts.aspx?BaseType=1">
<siteMapNode title="Google" url="http://www.google.com"/>
</siteMapNode>
</siteMapNode>
</siteMap>


This file will control the actual content of the navigation.

  • Modify the master page, add the following inside a SharePoint:DelegateControl, preferably right next to topSiteMap declaration.
<asp:SiteMapDataSource ShowStartingNode="true" SiteMapProvider="CustomXmlContentMapProvider"
id="xmlSiteMap" runat="server" />

  • Modify the master page, and change the SharePoint:AspMenu, with ID=TopNavigationMenu, change it's DataSourceID from "topSiteMap" to "xmlSiteMap".

Save and Run - your navigation on that site is now controlled via the XML file.