SharePoint Tip of the Day – Programmatically changing a SPWeb navigation settings without relying on the property bag


I used to follow Andre Vala advices to change the navigation settings of a specific SPWeb (cf http://blogit.create.pt/blogs/andrevala/archive/2008/12/06/SharePoint-Tip-_2300_24_3A00_-Changing-a-Web-Site_2700_s-Navigation-Settings.aspx) but recently I found that they can be set in a cleaner way by casting the SPWeb to a PublishingWeb and changing the relevant properties :

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.NavigationOrderingMethod = OrderingMethod.Automatic;
publishingWeb.NavigationAutomaticSortingMethod = AutomaticSortingMethod.CreatedDate;
publishingWeb.NavigationSortAscending = true;
web.AllowUnsafeUpdates = true;
publishingWeb .Update();
web.AllowUnsafeUpdates = false;

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s