RSS Feed Feed your read!

Bookmark and Share







Tag Cloud

ASP.NET Generic, Best Practices, Business Intelligence, Freeware Releases, InfoPath, Infrastructure, jQuery, Lunch & Learn Events, Project Server, Random, Reporting Services, Search, SharePoint Administration, SharePoint Business Analysis and Project Management, SharePoint Development, Silverlight, Social Networking, Speaking Events, White Paper Releases, Workflow Foundation,

Archives

June 2007 (3)
August 2007 (1)
November 2007 (2)
February 2008 (2)
April 2008 (5)
May 2008 (7)
June 2008 (8)
July 2008 (7)
August 2008 (3)
September 2008 (7)
October 2008 (1)
November 2008 (3)
December 2008 (3)
January 2009 (7)
February 2009 (5)
March 2009 (10)
April 2009 (2)
May 2009 (6)
June 2009 (3)
July 2009 (4)
August 2009 (6)
September 2009 (3)
October 2009 (9)
November 2009 (10)
December 2009 (1)
January 2010 (1)
February 2010 (3)
March 2010 (6)
April 2010 (2)
May 2010 (3)
June 2010 (4)
July 2010 (3)

How to enforce a consistent Top Navigation across your entire SharePoint farm 

Tags: SharePoint Development

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

 
Posted by Phillip S. Wicklund on 9-May-08
4  Comments  |  Trackback Url  | 0  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments


Phil Wicklundcommented onMonday, 9-Jun-2008
So - I realized pretty quickly that this is a crappy solution. The client I'm at has a tight production approval process, and it could take weeks to update this XML file that sits on the file system. NOT GOOD! So, I researched a bit and tried writing a custom SiteMapProvider that reads the Navigation properties out of the Root Site collection’s root web, and then sends that navigational structure back to the ASP Menu for its data source. However, I couldn’t get it to work. Next, I tried putting the XML sitemap file into a document library so end users could update the top nav without needing production change approval. But I couldn’t get the XMLDataSource to work over a URL. Please leave a comment if you could get either of those solutions to work – or if you have a better approach to enforcing a consistent top navigation across your SharePoint farm. Thanks All! Phil


Keith Dahlbycommented onTuesday, 10-Jun-2008
Phil ~ There are probably other options, but Site Settings and Central Admin use .sitemap files stored in %webapp%\_app_bin. The SiteMapProviders additions look like siteMapFile="_app_bin/filename.sitemap". Since you use CKS:EBE, I suggest you take a look at CKS.EBE.UpdateSitemap. It's a timer job that allows you to add entries to either Site Settings or Central Admin by modifying the .sitemap file (in EBE, called by the WebApplicationFeatureReceiver to add the "Blog Settings" link under "Site Settings"). The concept could probably be extended to support full manipulation of your own sitemap, or even to overwrite the file with the latest from a document library. I assume the changes could then be pushed out to every applicable web app on the farm, though I'm not sure exactly how that should be handled. I'll be at the Twin Cities SharePoint Camp on Saturday if you'd like to discuss. Regards ~ Keith


Brentcommented onSaturday, 26-Jul-2008
Hi, Did you ever find a satisfactory solution? Thank you, Brent


Phil Wicklundcommented onMonday, 28-Jul-2008
I did! And I hope to blog about it soon!

I havn't tried it yet, but I'm pretty confident you could populate the XmlDataSource object's XML parameter by using the result of a WebRequest object. So, you would point a WebRequest to a xml site map that is stored in a Document Library in SharePoint, and then throw the request result into the data source. With that, the top nav will update withing needing to make server file changes. Just update the document in the library! Way easier!

Bookmark and Share

Note: Facebook no longer sends notifications for comments, so it may be a number of days before I see your post. For urgent matters, click "Contact Me" on the top nav. More info: Click Here.