// Retrieved target xml data is not matching with source xml navigation types so changing navigation settings to get correct data. public void ChangeNavigationSettings(ClientContext cc, StandardNavigationSource gSource, StandardNavigationSource cSource) { TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(cc); taxonomySession.UpdateCache(); cc.Load(taxonomySession, ts => ts.TermStores); cc.ExecuteQueryRetry(); var navigationSettings = new WebNavigationSettings(cc, cc.Web); navigationSettings.GlobalNavigation.Source = gSource; navigationSettings.CurrentNavigation.Source = cSource; navigationSettings.Update(taxonomySession); try { cc.ExecuteQueryRetry(); } catch (Exception) // if termset not found then set newly created termset to managed navigation { TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore(); Microsoft.SharePoint.Client.Taxonomy.TermGroup group = termStore.GetTermGroupByName("TG_1"); // TG_1 is a term group mentioned in navigation_add_1605.xml Microsoft.SharePoint.Client.Taxonomy.TermSet termset = group.TermSets.GetByName("TS_1_1"); // TS_1_1 is a term set mentioned in navigation_add_1605.xml cc.Load(termStore); cc.Load(group, g => g.TermSets); cc.Load(termset); cc.ExecuteQuery(); if (StandardNavigationSource.TaxonomyProvider == gSource) { navigationSettings.GlobalNavigation.TermStoreId = termStore.Id; navigationSettings.GlobalNavigation.TermSetId = termset.Id; } if (StandardNavigationSource.TaxonomyProvider == cSource) { navigationSettings.CurrentNavigation.TermStoreId = termStore.Id; navigationSettings.CurrentNavigation.TermSetId = termset.Id; } navigationSettings.GlobalNavigation.Source = gSource; navigationSettings.CurrentNavigation.Source = cSource; navigationSettings.Update(taxonomySession); cc.ExecuteQueryRetry(); } }
/// <summary> /// Sets the current navigation asynchronous. /// </summary> /// <param name="web">The web.</param> /// <param name="source">The source.</param> /// <param name="displaySettings">The display settings.</param> public async Task SetCurrentNavigationAsync(Web web, StandardNavigationSource source, NavigationType displaySettings) { var targetWeb = web ?? _web; var ctx = targetWeb.Context; var settings = new WebNavigationSettings(ctx, targetWeb); settings.CurrentNavigation.Source = source; settings.Update(TaxonomySession.GetTaxonomySession(ctx)); ctx.Load(targetWeb, w => w.AllProperties); await ctx.ExecuteQueryAsync(); targetWeb.AllProperties["__CurrentNavigationIncludeTypes"] = ((int)displaySettings).ToString(); targetWeb.AllProperties["__NavigationShowSiblings"] = bool.TrueString; targetWeb.Update(); ctx.Load(targetWeb); await ctx.ExecuteQueryAsync(); }