Mittwoch, 7. September 2011

How to change the order in the SharePoint Foundation alternative SPSiteMapProvider

I was trying to improve the navigation for a customer without investing to much in money and time. I found a solution discribed in this blog:
Easy and Simple SharePoint 2010 Dropdown Navigation bar that works no scripts, no web.config, works on hosted providers

In summary: go to the masterpage and replace this part:
<SharePoint:AspMenu
      ID="TopNavigationMenuV4"
      Runat="server"
      EnableViewState="false"
      DataSourceID="topSiteMap"
      AccessKey="<%$Resources:wss,navigation_accesskey%>"
      UseSimpleRendering="true"
      UseSeparateCss="false"
      Orientation="Horizontal"
      StaticDisplayLevels="2"
      MaximumDynamicDisplayLevels="1"
      SkipLinkText=""
      CssClass="s4-tn"/>
    <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
        <Template_Controls>
            <asp:SiteMapDataSource
              ShowStartingNode="False"
              SiteMapProvider="SPNavigationProvider"
              id="topSiteMap"
              runat="server"
              StartingNodeUrl="sid:1002"/>
        </Template_Controls>
    </SharePoint:DelegateControl>

with this:
<SharePoint:AspMenu
 ID="SPSiteMapProvider"
 Runat="server"
 EnableViewState="false"
 DataSourceID="SiteMapDataSource1"
 AccessKey="<%$Resources:wss,navigation_accesskey%>"
 UseSimpleRendering="true"
 UseSeparateCss="false"
 Orientation="Horizontal"
 StaticDisplayLevels="2"
 MaximumDynamicDisplayLevels="3"
 SkipLinkText=""
 CssClass="s4-tn"/>
 <asp:SiteMapDataSource runat="server" ID="SiteMapDataSource1"/>
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
 <Template_Controls>
 <asp:SiteMapDataSource
 ShowStartingNode="False"
 SiteMapProvider="SPSiteMapProvider"
 id="topSiteMap"
 runat="server"
 StartingNodeUrl="sid:1002"/>
 </Template_Controls>
</SharePoint:DelegateControl>
Unfortunately this Navigation provider sort the Items using ASCII order. He don't care about the order defined in the ToNavigationConfiguration interface.

So how can I sort the sites anyhow? Just add whitespaces to the title of the Web that you want to be on the first. Example:

Pages with the titles "First", "Second", "Third", "Fourth" and "Fifths" will be shown in this order:
"Fifths", "First", "Fourth", "Second", "Third"
To get them in the right order change the name to this:
"    First", "   Second", "  Third", " Fourth" and "Fifths"

And don't worry the whitespaces are trimmed in both the Navigation and the Page title.

It's not the most elegant way, but it works.

Enjoy and share

4 Kommentare:

  1. Thanks... It was exactly what i was looking for!

    AntwortenLöschen
  2. I was a little to quick there, I tried it now and I can't get it to save the web title with whitespaces. When I click save the whitespaces are removed??

    Please let me know where you change it and how you are able to save with whitespaces.

    Regars Kristian

    AntwortenLöschen
    Antworten
    1. Hi Krillehbg,

      If the whitespaces are removed when you create the sub web, then go to the site actions and change the title after creating the web. You can add the whitespaces and they will be kept.

      Löschen
    2. Hi....that don't work in WSS3.0. Any suggestions? All whitespaces are removed when save the title modification.

      Löschen