Wednesday, April 16, 2008 6:01 PM Jan Tielens

Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

UPDATE: If you want to add breadcrumbs to pages provisioned in the SharePoint Central Administration site, read the follow post: http://weblogs.asp.net/jan/archive/2008/10/10/adding-breadcrumb-navigation-to-application-pages-in-sharepoint-central-administration.aspx

A while ago I posted an article about how you could build custom Application Pages for SharePoint that display the breadcrumb navigation, just like all the out-of-the-box Application Pages do. The trick was to add add a siteMapNode element in the layouts.sitemap located in the _app_bin folder of the SharePoint site. It's no problem to do this manually; just open the file in Notepad/Visual Studio add the siteMapNode in the desired parent node (e.g. Site Settings) and you're done. But in a production environment (especially with multiple front end web servers in the farm) you don't want to do this manually! Of course this can be done from a Feature handler; open the layouts.sitemap XML file in an XMLDocument, add the siteMapNode element and save it again. It sounds easy, but it gets complex again when you have multiple front end web servers; the code to change the layouts.sitemap should be updated on all those servers. A solution for this problem is to create a job definition that executes a job on all the servers. An example of this approach can be found over here.

The scenario described above is still quite complex; but a reader of my blog discovered that SharePoint actually has a built-in mechanism which is much easier to implement! First of all you need to create a file with a name formatted like layouts.sitemap.*.xml (the * can be anything), e.g. layouts.sitemap.demoapppages.xml. This file should be copied to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS folder. In this file you can put siteMapNode elements that should be added to the layouts.sitemap file, for example:

<?xml version="1.0" encoding="utf-8"?>
<siteMap>
    <siteMapNode url="/_layouts/demopage.aspx"
    parentUrl="/_layouts/settings.aspx" title="Demo App Page"/>
</siteMap>

The parentUrl attribute determines where the siteMapNode will be added in the hierarchy of the original layouts.sitemap file (in this case beneath the Site Settings page). SharePoint will merge the contents of layouts.sitemap.demoapppages.xml when a new Web Application is created (thus the layouts.sitemap file is created in the _app_bin folder). To force the layouts.sitemap file to be recreated for the existing Web Applications as well, you can use the copyappbincontent operation of the STSADM tool:

STSADM -o copyappbincontent

Or you can use the ApplyApplicationContentToLocalServer method of the SPWebService class (typically in a Feature Receiver):

public class FeatureHandler : SPFeatureReceiver
{
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
       SPFarm.Local.Services.GetValue<SPWebService>().
                    ApplyApplicationContentToLocalServer();
    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {}

    public override void FeatureInstalled(SPFeatureReceiverProperties properties) {}

    public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {}
}

I've created a small sample project on MSDN Code Gallery to show everything in action, that has the following components:

  • Custom Application Page (demopage.aspx), deployed to the _layouts folder
  • Custom SiteMap (layouts.sitemap.demoapppages.xml)
  • Feature, scoped to the web application level, that adds a link to the custom application page in the Site Settings page
  • Feature event handler to trigger the merging of all the sitemap files

So thanks Brian Staton for sharing your tip!

Comments

# Adding Breadcrumb Navigation for SharePoint Application Pages - Jan Tielens&#39; Bloggings

Pingback from  Adding Breadcrumb Navigation for SharePoint Application Pages - Jan Tielens&#39; Bloggings

# Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way | videositemap.com

Pingback from  Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way | videositemap.com

# re: Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

Wednesday, April 16, 2008 1:29 PM by Alex Dresko

Dang.. that's smarts!

# re: Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

Thursday, April 17, 2008 7:44 AM by iwkid

We took a similar approach when building TweakSP (www.tweaksp.com).  Check out the DeploymentUtilities in the TweakSP.Deployment project as well as the AdminFeatureReceiver for another example.

# re: Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

Friday, April 18, 2008 3:57 PM by Paul Schaeflein

When deactivating, do you need to call ApplyApplicationContentToLocalServer() again?

Although, I'm not sure if the layouts.sitemap.*.xml would be removed before the FeatureDeativating method is run.  Perhaps Feature Uninstalling would be better...

# re: Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

Sunday, April 20, 2008 11:15 PM by sinkfish

Hello,I met some problems when using your smartpart to add ajax user control.I have installed WSS SP1、MOSS SP1、ASP.NET Ajax Extensions,and I have configed the web.config file.But my ajax user control can't show normally.For example,when I push the button as you show in the demo video,it didn't work,means that it just do nothing.Sincerely need your help!Thanks!

sink@live.cn

(China)

# re: Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

Monday, April 21, 2008 2:00 AM by Jan Tielens

@Paul: yes, the file needs to be removed, so the uninstall even should be ok.

@sinkfish: please post your question in the SmartPart forums.

# ??ghyBlog &raquo; links for 2008-04-27

Sunday, April 27, 2008 6:32 PM by ??ghyBlog » links for 2008-04-27

Pingback from  ??ghyBlog &raquo; links for 2008-04-27

# Application Pages BreadCrumb and how world is connected

Monday, April 28, 2008 12:41 PM by Imagine Think Create Share

Hi, Sometimes I wonder how different people get the same results with no communication between them.

# re: Adding Breadcrumb Navigation to SharePoint Application Pages, the Easy Way

Tuesday, May 20, 2008 2:14 PM by Jeroen Ritmeijer

Weird, the stsadm command has the desired effect, but somehow the line of code in FeatureActivated has no effect. The line is executed though, I have traced through it.

STSADM -o copyappbincontent

and

SPFarm.Local.Services.GetValue<SPWebService>().

                   ApplyApplicationContentToLocalServer();

# SharePoint Breadcrumbs - Sample of differences, chart of uses and resources

Wednesday, August 13, 2008 5:43 PM by Heather Solomon - MVP, WSS - SharePoint Branding and Design

SharePoint Breadcrumbs - Sample of differences, chart of uses and resources

# SharePoint Breadcrumbs - Sample of differences, chart of uses and resources

Wednesday, August 13, 2008 6:00 PM by Heather Solomon's Mirrored Blog

I don&#39;t think I am alone when I say &quot;I hate the page level breadcrumb in SharePoint&quot;. While

# Adding Breadcrumb Navigation to Application Pages in SharePoint Central Administration

Friday, October 10, 2008 2:33 AM by Jan Tielens' Bloggings

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso

# Adding breadcrumb navigation to Application Pages in SharePoint Central Administration &laquo; Devblog of Bart Snyckers

Pingback from  Adding breadcrumb navigation to Application Pages in SharePoint Central Administration &laquo; Devblog of Bart Snyckers

# 为Sharepoint应用程序页添加面包屑导航

Saturday, January 31, 2009 7:13 AM by laputa'sky

# The ApplyApplicationContentToLocalServer Method and Why It Comes Up Short &laquo; SharePoint Interface

Pingback from  The ApplyApplicationContentToLocalServer Method and Why It Comes Up Short &laquo; SharePoint Interface