My Breadcrumbs have "> Pages > default.aspx" in them

I’ve written about this before, but really it was just an addendum to another point I was trying to make. It might be worth bringing out as a post in itself.

ASP.NET navigation controls take data from a navigation provider, and render it into HTML. The breadcrumbs used in SharePoint use the one navigation control, but give it different navigation providers…

… the point relevant to whether or not the “> Pages > default.aspx” is displayed in the breadcrumbs is the SiteMapProvider. The CurrentNavSiteMapProviderNoEncode provider doesn’t seem to include the ‘Pages’ bit of the path – hence it is used by the page layouts. The Default.master’s SPContentMapProvider provides a breadcrumb that includes the ‘Pages’.

So, if your page is using a breadcrumb such as…

<asp:SiteMapPath id="ContentMap" SiteMapProvider="SPContentMapProvider" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" runat="server"/>

… then your breadcrumb will include the “> Pages > default.aspx”. Note that this is the default content of the breadcrumb in default.master. Thus, if you’re creating a brand new page layout, you’ll probably want to override that content using an ASP.NET Content control something like this…

<asp:Content ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server">

<asp:SiteMapPath ID="siteMapPath" SiteMapProvider="CurrentNavSiteMapProviderNoEncode" RenderCurrentNodeAsLink="false" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" Runat="server"/>

</asp:Content>

This code defines a content control that overrides the default content for the Title Breadcrumb. It uses the CurrentNavSiteMapProviderNoEncode (nice name!) navigation provider, and so won’t show the “> Pages > default.aspx” bit in the breadcrumb.

So, in short, when you’re creating a new Page Layout, make sure you override the Title Breadcrumb with something that uses the CurrentNavSiteMapProviderNoEncode provider.

My Breadcrumbs have "> Pages > default.aspx" in them

15 thoughts on “My Breadcrumbs have "> Pages > default.aspx" in them

  1. Hi Andy,

    Thanks for the article. It almost solved my problem and saved lot of time. Thanks for the efforts you have put in.

    I’m facing another problem with this now. At site collection level it just displays “Home” at all the times on all the publishing pages. It works fine for subsite. e.g for Products site it displays it like this “Home > Products > Intro” which is absolutely right. But the problem is first level site (i.e. site collection level) where it just displays “Home” for all the pages.

    I’ll appreciate any help on this.

    Thanks,
    Sumit

    Like

  2. Hi Sumit,

    No problem, it’s nice to help out.

    Well, there are a couple of options for your top level site breadcrumbs, but first – do you _really_ want to do that?

    I’ll assume your top level site has the publishing features enabled (if not, the “Pages > default.aspx” thing wouldn’t have been a problem!) That site has a Pages Library called ‘Pages’, and a Page in it with the file name default.aspx then.

    As you’ve noticed, if you go to your top level site, you get shown the pages/default.aspx page, and this has a single link back to your top level site on it, which you don’t really want. If you click on that link, it takes you ‘back’ to the page that you’re already at.

    However, the Pages Library of your top level site could have other Pages in it, and it does make sense for these to have a breadcrumb link to the pages/default.aspx page. Yes, you could get there through the top navigation bar, but this isn’t as intuitive.

    If you’re happy with the information that you’re at the Home page, but you don’t want the ‘Home’ title rendered as a link, you might want to consider your settings on the breadcrumb control for the RenderCurrentLink option. See: http://www.novolocus.com/2008/05/08/breadcrumbs-rendering-the-current-link/

    If you really don’t want that text ‘Home’ at all, and it really bugs you, though, there are some options.

    The ‘proper’ way of dealing with this would be to write a new SiteMapProvider, install it, add it to your web.config and then use it in your pages. You would have to start from scratch, I suspect – there doesn’t seem to be a CurrentNavSiteMapProviderNoEncode class to subclass (it seems to be part of the PortalSiteMapProvider Class )

    (At least, that should be possible – I’ve never tried, but it looks right)

    There is an interesting article from Rich Finn which might be useful:

    http://blog.richfinn.net/2007/08/14/CustomCMOSSNavigationUsingPortalSiteMapProvider.aspx

    Also Shantha Kumar has a list of the Nav providers used in SharePoint, which is pretty interesting.

    http://ktskumar.wordpress.com/2008/04/14/sharepoint-navigation-providers-part-1/

    Alternatively, the hack approach would be to use some Javascript to get the onetidPageTitleAreaTable, then find the breadcrumb within, then examine how many links there are, and decide whether to set the visibility of the breadcrumb to hidden. But that really does sound like a hack.

    Like

  3. Divyesh says:

    Hi Andy,

    i have one question for you regarding the breadcrumb,i am new to sharepoint and would like to learn more from you.i have one root site and subsite on top navigation.i do have access on subsite.i dont have access on root site,but once i click on subsite.i got the breadCrumb such as “Home->HR”

    so is there any way to remove “Home” from Breadcrumb?

    i will bevery thankfl to you if you solve my doubt.

    Thank You
    Divyesh Jadeja

    Like

  4. Mike Gallagher says:

    Hi Andy,
    Great article!

    Is there a way to show the Top Level site as a link?

    I want to hardcode in a Home link, and have the current site appear in the navigation after this. Like this:

    Home >
     

    The problem with this is that when I’m in the current site, nothing appears until i move to a lower level – doc library, or sub-site.

    The control seems to be hiding the top-level site. Is there a way to turn this back on?

    Thanks!

    Mike

    Like

  5. Yup, that’s possible. It does mean editing the code in your page. If you look at the ASP:SiteMapPath control, you’ll notice it has an attribute ‘RenderCurrentNodeAsLink’. Set that to ‘true’.

    Now, the complicated bit is, where do you have to do that?

    Well, the first place is in your master page, if you’re wanting this behaviour for non-publishing pages.

    The second is, if you are using publishing pages, all of the page layouts which supply their own breadcrumb. For example, the DefaultLayout.aspx page does this – the breadcrumb from the master page is blanked out, and then a new breadcrumb is defined in the page layout itself.

    I’ll leave you to find all the locations you have to do that – but it should work!

    Like

  6. Mike says:

    Andy,
    It seems to me that there are 2 main options for default rendering of breadcrumbs at the page level:

    1) Use the SPContentMapProvider. Example: Company > Pages > MyPage.

    2) Use the SPCurrentNavMapProviderNoEncode. Example: Company.

    What I’d like to see is a hybrid of the two. For example, I’d like to see the breadcrumb as Company > Mypage.

    Is that possible from a default provider or do I need to roll my own?
    Thanks,
    Mike

    Like

  7. SPCurrentNavMapProviderNoEncode already does that – except for the home page of a site, where it doesn’t show the ‘> MyPage’ bit

    If MyPage is not the site’s home, it’ll do what you want. I imagine you can see why – otherwise the site’s home page looks like it is a page within the site (from a navigational standpoint – clearly, it really is just another page within a site!)

    To prove it, create another page (MyPage2) . Go to it, note the breadcrumb.
    Now set MyPage2 as the site home page. Now go to MyPage – note the breadcrumb.
    And now go MyPage2 – note that the breadcrumb has changed.

    Hope that helps?

    Like

  8. bhargavi says:

    Hi Andy, thanks for a valuable post.

    I have a requirement to change the user name in the breadcrumb for MySite.
    Generally the bread crumb displays the site collection admin name, is it possible to change?

    hope u can help

    -Bhargavi

    Like

  9. Um, I’m pretty sure that the Breadcrumb is the name of the owner of the mysite! I think each user’s mysite is a separate Site Collection. Hence, the site collection admin is the user’s name which is the name of the site collection, and so is in the breadcrumb.

    Have you tried logging into a mysite as a different user?

    Like

  10. Michael Beaver says:

    I tried using CurrentNavSiteMapProviderNoEncode and got errors about remote authoring is not in use…What does this mean? It effects not only breadcrums, but the ribbon and other controls.

    Like

  11. I’m not familiar with that error. Were you trying to edit that via SharePoint Designer? It sounds like maybe it’s use has been restricted?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s