Programmatically Sorting Top Navigation Menu in MOSS 2007

You can easily sort the Top navigation bar in MOSS 2007 by going to Settings -> Navigation in your root level Web

Sorting Navigation in MOSS 2007

Programmatic access to proprieties for Navigation sorting is buried within Microsoft.SharePoint.Publishing.PublishingWeb namespace in Microsoft.SharePoint.Publishing assembly!

There are three properties for Navigation sorting

1. NavigationOrderingMethod

2. NavigationSortAscending

3. NavigationAutomaticSortingMethod

here is sample code that sorts the navigation menu by Created Date of Sub-Webs

</p> <p>using (SPSite site = new SPSite("http://localhost"))<br /> {<br />                using (SPWeb web = site.RootWeb)<br />                {<br />                     PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);<br />                     pubWeb.NavigationOrderingMethod = OrderingMethod.Automatic;<br />                     pubWeb.NavigationSortAscending = true;<br />                     pubWeb.NavigationAutomaticSortingMethod = AutomaticSortingMethod.CreatedDate;<br />                     web.AllowUnsafeUpdates = true;<br />                     pubWeb.Update();<br />                     web.AllowUnsafeUpdates = false;<br />                }<br />  }</p> <p>

Advertisements

2 thoughts on “Programmatically Sorting Top Navigation Menu in MOSS 2007

  1. How do i find out the current SET order the subsites?
    Say i had
    -Root
    –SiteA
    ——Site3
    ——Site1
    ——Site2
    –SiteB
    ——Site1
    ——Site3
    ——Site2

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