Configure Site Navigation via CSOM

We would like to configure site navigation when a new site got created using CSOM. 
Here is the code I figured it out.
using(ClientContext ctx = new ClientContext(siteUrl)
   Web web = ctx.Web;
   TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
   WebNavigationSettings webNavSettings = new WebNavigationSettings(ctx, web);
   webNavSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;
   webNavSettings.CreateFriendlyUrlsForNewPages = false;

   // show only current site's navigation items in current navigation
   web.AllProperties["__InheritCurrentNavigation"] = "False";
   web.AllProperties["__NavigationOrderingMethod"] = "2";
   web.AllProperties["__NavigationShowSiblings"] = "True";
   web.AllProperties["__CurrentNavigationIncludeTypes"] = "3";
   web.AllProperties["__CurrentDynamicChildLimit"] = "100";

   // show subwebs and pages in navigation
   web.AllProperties["__IncludeSubSitesInNavigation"] = "True";
   web.AllProperties["__IncludePagesInNavigation"] = "True";




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