Sharepoint2013 Site - CSOM - Update Navigation Settings

4.7k Views Asked by At

We need to update Global and Current Navigation Settings for the site. Below is our code

var publishingWeb  = PublishingWeb.GetPublishingWeb(this.CC, subWeb);

                    // WebNavigationSettings
                    var webNavigationSettings = new WebNavigationSettings(this.CC, subWeb);
                    webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.PortalProvider;
                    webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;

                    // CSOM don't have: publishingWeb.Navigation.GlobalIncludeSubSites.
                    subWeb.AllProperties["__GlobalIncludeSubSites"] = "True"; //TODO: Verify why it is not working. 
                    subWeb.AllProperties["__GlobalIncludePages"] = "True"; //TODO: Verify why it is not working.

                    subWeb.Update();
                    webNavigationSettings.Update(tSession);

                    CC.Load(subWeb, WEB_INCLUDES);

                    // Apply the load
                    CC.ExecuteQuery();

As we are using CSOM, we did not have

publishingWeb.Navigation.GlobalIncludeSubSites

. So we tried to set using AllProperties to set GlobalIncludeSubSites and GlobalIncludePages.


But those properties are not getting set. Is there any way to fix this problem. I went throught article http://discoveringsharepoint.wordpress.com/2013/03/19/programmatically-set-navigation-settings-in-sharepoint-2013/ But it uses namespace : Microsoft.SharePoint.Publishing.Navigation


But our's namespace is : Microsoft.SharePoint.Client.Publishing.Navigation As we are doing from client server object model. Is there any way to solve this ? Thanks

1

There are 1 best solutions below

0
On

In SharePoint 2013 was introduced a new Microsoft.SharePoint.Client.Publishing and Microsoft.SharePoint.Client.Publishing.Navigation namespaces in CSOM API. But unfortunately it is not supported to modify navigation settings using WebNavigationSettings class since properties are exposes as a read-only.

You could utilize the following approach for that purpose. ClientPortalNavigation.cs represents a CSOM counterpart for SSOM PortalNavigation Class.

The following example demonstrates how to utilize that class and update Navigation settings:

using (var ctx = new ClientContext(webUri))
{

    var navigation = new ClientPortalNavigation(ctx.Web);
    navigation.CurrentIncludePages = true;
    navigation.GlobalIncludePages = false;
    navigation.SaveChanges();   
}

ClientPortalNavigation.cs is compatible with SharePoint 2010/2013 CSOM APIs.

References