Depending on your organization's taxonomy, you very likely have many SharePoint Sites across many Site Collections, or even Web Applications. A good way to help your end users navigate your farm is to create a consistent top navigation across all your SharePoint sites. By default the top navigation is set on a site collection by site collection basis, and if you have hundreds or worse, thousands, of site collections, this can create a confusing experience for those end users.
A compelling solution to this would be to write a custom SiteMapProvider that crawls a specific site collection and retrieves the navigational elements within, and all other site collections within the farm utilize that for its top navigation data source. I didn't have time to write this, so I went with a more simplistic approach which is to use a XmlDataSourceProvider to retrieve a site map stored on the server. Read further to see how I accomplished this…
In the default.master file in the 12 Hive, search on "SharePoint:AspMenu". This is the SharePoint class that is extending the base AspMenu class:
Figure 1: SharePoint AspMenu code
What we're going to do is change this back to the base AspMenu class, and change the data source to be an xml site map file on the server. Notice on line 110 the"DataSourceID" key. This key corresponds to the SiteMapDataSource on line 134. That data source is using the SPNavigationProvider which is pulling the navigation elements out of the sites top navigation properties. You could extend this class to target a specific site, if you didn't want to use an xml file, or if you still wanted your end users to be able to edit the navigation elements.
For now, we're going to delete lines 132-141 and replace them with our own data source. Use the following code to define your data source:
<asp:XmlDataSource DataFile="/_layouts/contoso/contosoTopNavSiteMap.xml" ID="DemoXmlDataSource" runat="server" XPath="/*/*" />
This data source is linking to an XML file in the 12 Hive layouts directory.
Next, right after line 130, add the following data bindings:
<DataBindings>
<asp:MenuItemBinding Depth="0" DataMember="siteMapNode" NavigateUrlField="url" TextField="title" ToolTipField="description" ValueField="title" />
<asp:MenuItemBinding Depth="1" DataMember="siteMapNode" NavigateUrlField="url" TextField="title" ToolTipField="description" ValueField="title" />
</DataBindings>
These bindings are used to tie elements in the XML site map file, to required properties in the ASP menu's data source. For instance, set the AspMenu "TextField" property to the "title" property in the site map.
Lastly, change the DataSourceID on line 100 to be "DemoXmlDataSource", the ID of the XML data source that is pointing to our XML file.
Now all we need to do is save the master page to the 12 Hive and deploy our site map into the Layouts directory. Here is some sample XML I used for my site map.
Here's my AspMenu when all said and done.
Example (notice the style sheets keep the new top nav looking much the same as before):
Figure 2: screen shot of new top nav
Phil