Adding Breadcrumb Navigation for SharePoint Application Pages
UPDATE: Also read my follow-up post: http://weblogs.asp.net/jan/archive/2008/04/16/adding-breadcrumb-navigation-to-sharepoint-application-pages-the-easy-way.aspx
Application Pages in SharePoint 2007 are a great way to extend SharePoint’s default user interface for your custom SharePoint solutions. An application page is deployed once per Web server and it’s not possible to customize these pages per site (like the normal Site Pages). A good example of an Application Page is the default Site Settings page: every site has one, and it’s not customizable on a per site basis (although the contents can be different for sites). A very basic application page could look like:
<%@ Page MasterPageFile="~/_layouts/application.master"
Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase"
Language="C#"%>
<asp:Content
contentplaceholderid="PlaceHolderPageTitle" runat="server">
Jan's Page
</asp:Content>
<asp:Content
contentplaceholderid="PlaceHolderPageTitleInTitleArea"
runat="server">
Jan's Page
</asp:Content>
<asp:Content
contentplaceholderid="PlaceHolderMain"
runat="server">
Jan's fantastic Application Page content goes here!
</asp:Content>
When this ASPX page is saved in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS folder, it can be accessed from any site by making use of the following URL: http://siteurl/optionalsubsite/_layouts/pagename.aspx.
(More information about creating your own Application Pages can be found in Ted Pattison's excellent Visual How-To) As you can see, this page resembles the Site Settings page (or any other default Application Page) quite well. But there is one important thing missing: the breadcrumbs above the page title! Check for example the default Site Settings page:
You can’t fix this by adding a breadcrumb control (aka SiteMapPath control) to the Application Page, actually there is already a breadcrumb on the page (defined in the default master page), the issue is that the new Application page is simply not known by the navigation infrastructure. Luckily this is quite easy to solve: SharePoint uses the ASP.NET 2.0 navigation functionality, so you just have to update the site’s sitemap. This is an XML file containing the navigation hierarchy and is located in C:\Inetpub\wwwroot\wss\VirtualDirectories\wss.u2ucourse.com\_app_bin\layouts.sitemap. If you want that your Application Page behaves as a sub page of the Site Settings page (a common scenario for Application Pages), look for the siteMapNode of the settings page:
<siteMapNode title="$Resources:wss,settings_pagetitle" url="/_layouts/settings.aspx">
And add your own siteMapNode as a child element:
<siteMapNode title="Jan's Page" url="/_layouts/jan.aspx"/>
Et voila, the custom Application Page’s breadcrumb control will automatically display the correct breadcrumb links. Of course modifying the layouts.sitemap file manually is not very nice since a SharePoint environment could have more than one web application (potentially on different servers), so you’d have to edit a couple of files. But of course you can automate this as well, I’ll go into the details in a follow-up post.
UPDATE: Also read my follow-up post: http://weblogs.asp.net/jan/archive/2008/04/16/adding-breadcrumb-navigation-to-sharepoint-application-pages-the-easy-way.aspx