Click to Rate and Give Feedback

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (3)
How to: Customize Navigation

Most Web sites employ some form of customized user interface (UI) that provides users with visual clues on how to navigate in the site more easily, and find the information they need. Although the look and feel (or branding) can vary from site to site, the same basic navigation elements are usually present, such as navigation bars and menus that expose options a user can choose to navigate to a subsite or page.

This set of topics describes how Microsoft Office SharePoint Server 2007 navigation works and some ways you can customize it programmatically and through the UI, including:

  • Using the provider and data source APIs to customize the structure and behavior of vertical and horizontal menus.

  • Understanding Navigation Settings UI options and using them to set up a site navigation hierarchy.

  • Replacing the default navigation provider included in Office SharePoint Server 2007 with your own custom provider.

  • Configuring multiple navigation providers for a site.

Navigation Fundamentals

To make it easy to build effective navigation elements such as horizontal and vertical menus and breadcrumb navigation, Office SharePoint Server 2007 takes advantage of Microsoft ASP.NET 2.0 pluggable navigation—the Provider model. The Provider model defines a provider as a software module that provides a uniform interface between a service and a database. Providers abstract storage media in much the same way that device drivers abstract physical hardware devices, and you can use them to store state data virtually anywhere. For example, by developing custom providers, you can store state data in a variety of external data providers, such as front-end Web services, XML files, and databases. The navigation API includes a site map provider that abstracts site map data, and a data source object that maps and filters navigation structure and data from the provider for presentation in navigation UI Web controls. Both the provider and data source API include properties you can get and set that enable flexible, dynamic options for customizing your site.

Office SharePoint Server 2007 navigation is site-centric, meaning that each Web site in a site collection can determine the way the application displays each navigation item beneath it in the site hierarchy: all the way down to the next site. As a result, each site has several navigation options that you can set through the UI or programmatically.

You can create the navigation you want by determining in advance the hierarchy you want for the Web sites and pages you are creating, and by either fine-tuning the hierarchy by using the Navigation Settings page available through the Site Actions menu or Site Settings page in Office SharePoint Server 2007.

The default navigation system is based on the hierarchy for the site, and the navigation through the site occurs based on choices made through the UI or programmatically. Options you can set include whether to show subsites and pages in navigation, whether to sort navigation items manually or automatically, and how to handle individual sorting and display attributes and behavior of individual navigation items.

When you define vertical and horizontal menus, you can deploy a section of the navigation with one or more static or dynamic menu levels:

  • Static menu items represent levels of hierarchy and are usually hyperlinked. You can create additional levels of static and dynamic menu items under the top-level navigation item (the root).

  • Office SharePoint Server 2007 creates dynamic—fly-out—menu options based on site structure. The site hierarchy defines the levels in the navigation menu.

Your site can have any number of static and dynamic levels.

By design, navigation controls detect their location in a site structure, and use a complex method to determine the order in which to return nodes from the data store. When you sort navigation items, Office SharePoint Server 2007 first returns nodes from the data store and then sorts the navigation items.

See Also

Reference

Microsoft.SharePoint.Publishing.Navigation
Microsoft.SharePoint.Navigation

Other Resources

How to: Work with Menus and Navigation Objects
How to: Modify Navigation Settings through the UI
How to: Customize Navigation Controls and Providers
Best Practices: Using Disposable Windows SharePoint Services Objects

Community Content   What is Community Content?
Add new content RSS  Annotations
Couple of comments      Hector Mike ... Tony Willeto   |   Edit   |   Show History

Hi Hector,

I also have been using navigation, except I'm gathering info from the Links list and creating a menu from that. It does ok but 2 problems - 1) the column title appears on the webpart (whereas I want the field values of the column to appear as the 1level of the menu, then the URLs as 'hoverover'; and 2) can't quite get it to work for 2-level 'group by'. As a reminder, the Links list allows 2 levels of grouping. So some users are using 'category' then sub-category' or 'chapter' and 'section' to indicate a 2 level of categorization of the links.

hoping much success!!!

Tony Willeto

I had to use SPSite mySite = new SPSite(this.CurrentSite.Url + pNode.Url), because pNode.Url = "\". This was causing an error "UriFormatException: Invalid URI: The format of the URI could not be determined."

I had to switch two arguments of the SiteMapNode constructor to become SiteMapNode childNode = new SiteMapNode(this, listUrl, listUrl, list.Title).

I could not just add a child node of type SiteMapNode to the collection, as this caused a casting error (could not cast from SiteMapNode to PortalSiteMapNode) downstream. I could not cast one to the other in code either with an explicit case or using the 'as' keyword, since this generated an exception at runtime stating that 'Value of value may not be null'. I tried to use base.AddNode(navnode, pNode), but it generated a 'Not implemented' exception. Through experimentation I came up with the following, which allows the code to run fine, though I am not confident that it produces the results the author of this article intended:

                    SPSite mySite = new SPSite(this.CurrentSite.Url + pNode.Url);
SPWeb currentWeb = mySite.OpenWeb();
SPListCollection lists = currentWeb.Lists;
foreach (SPList list in lists)
{
string listUrl = list.DefaultViewUrl;
SiteMapNode navnode = new SiteMapNode(this, listUrl, listUrl, list.Title);
PortalWebSiteMapNode pwsn = pNode as PortalWebSiteMapNode;
if (pwsn != null)
{
PortalSiteMapNode psn = new PortalSiteMapNode(pwsn, listUrl, NodeTypes.Area, listUrl, list.Title, "My description");
nodeColl.Add(psn);
}
}
                    return nodeColl;

Since no one has posted anything here, I would be interested to know if this is simply the result of a difference in configuration between what I have and what was used to produce the sample, or due to a difference in the final MOSS 2007 product from the beta, or ...

Yep, Me too      phydroxide   |   Edit   |   Show History

Tony,

I actually struggled with this quite a bit until I noticed your post. I got the error UriFormatException, and would be interested to know how you narrowed it down to the line of code containing pnode.Url (SharePoint has not been easy for me to debug)

My code worked right away because I was using the asp:SiteMapProvider control in my page layout. When I tried to change it to

<PublishingNavigation:PortalSiteMapDataSource ... /> 

I got the same error "could not cast from SiteMapNode to PortalSiteMapNode. I fixed the problem approximately as you described, and once again paid closer attention to your post to realize you already ran into the same problem. Ultimately my code looks nearly the same as yours.

One difference is if you use PortalSiteMapNode as the first node you don't have to prepend the CurrentSiteURL

									
Tags What's this?: Add a tag
Flag as ContentBug
Setting same nav items across a site's web hierarchy      Alex Angas   |   Edit   |   Show History

I recently needed to display the same left navigation for a publishing site at every point from a certain web and below. A neat way I discovered was by using StartFromCurrentNode="false" and setting StartingNodeOffset.

   <PublishingNavigation:PortalSiteMapDataSource ID="SiteMapDS" Runat="server"
SiteMapProvider="CurrentNavSiteMapProvider" EnableViewState="true"
StartFromCurrentNode="false" StartingNodeOffset="3" ShowStartingNode="false" />

By putting this code in the master page, webs and pages from the third level down within the site's topology are always shown for any page or layout attached to that master page. SharePoint knows to display the nav links in context of where you are in the site.

This codes does not cleanup it's SPWeb and SPSite objects      Pete Rodriguez   |   Edit   |   Show History
If you use this code sample, be aware that the SPSite and SPWeb objects are not being properly disposed and you could experience memory and resource utilization issues under load. See the following article for more information: http://msdn2.microsoft.com/en-us/library/aa973248.aspx
Tags What's this?: Add a tag
Flag as ContentBug
subclass PortalSiteMapProvider is not working      Hany Kamel   |   Edit   |   Show History

I tried subclassing PortalSiteMapProvider. I added new assembly to GAC and to bin folder of web site. Then I added following line to web.cofing:

<add name="NSiteMapProvider" description="HK provider" type="HKSharePoint.CustomNavProviderWithList, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b81fcc045e68c0d" />

I got error:

0x1438 Windows SharePoint Services General 8sl1 High DelegateControl: Exception thrown while adding control 'Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapDataSource': System.Configuration.ConfigurationErrorsException: The given assembly name or codebase was invalid

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker