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 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;

Leave a Reply

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

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