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 

7 Comments

  • Jan... thats exactly what I was looking for. Thanks mate!

  • What if you dont have breadcrumbs showing...A custom template that for some reason doesn't show any breadcrumbs. I would like to know where to check for them....

  • HI
    a great atricle. but can u give better approach how to do the dode behind.
    is there a better approach than this
    compile the site into a single dll , deployt he dll in thebin and then copy the aspx to the _layouts folder and then modify the webconfig to reister the safe controlls r asemblies.
    what is the best approach ,How do we add the code behing and file or a different class to register to add functionality tog the content pages.


    in vss 2005 we can compile int oindividual seperate asemblies with stong name . and deploy them seperately or into one assembly into gac. which one do u think the best way.
    thanks
    gmail001

    thanks
    gmail001

  • Good artcile, But this not the right way of doing it, in the sense that you are editing files in 12 Hive which is owned by Microsoft.

    This will work for testing purposes, but move same thing to a shared production environment will be a big challenge ...

  • Hi Jan,

    I think your article is fantastic. And it really saved my day. I was planning to do the same with the help of custom feature and creating my custom navigation.

    Eagerly awaiting your post on automated deployment of your approach in a farm/production scenario

  • how can i add breadcrumb to site pages or custom pages? I am adding custom pages by addign the new link in top menu bar using feature. I will be very helpful to me if anybody can answer this.Thanks in advance.

  • How about breadcrumb navigation for sub-sites? How would one accomplish that task?

Comments have been disabled for this content.