by
0
6
1,335
0
Top 1% !
Famous
Easy-to-find
Specified
Tuned
OpenSource
Popularity: 19069th place

Published on:

InputName0clientContext
InputName0testContext
InputName1taxonomySession
InputName2web
InputType0ClientContext
InputType0TestContext
InputType1TaxonomySession
InputType2SPWeb
InputType2Web
LanguageCSharp
LicenseMIT_X11
MethodNameRecreateSampleNavTermSet
OSWindows
OutputTypeNavigationTermSet

RecreateSampleNavTermSet

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/284891/RecreateSampleNavTermSet?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.SharePoint; using System.Diagnostics; using Microsoft.SharePoint.Taxonomy; using Microsoft.SharePoint.Publishing.Navigation; using System.Net; public static NavigationTermSet RecreateSampleNavTermSet(TestContext testContext, TaxonomySession taxonomySession, SPWeb web) { Console.WriteLine(testContext, "RecreateSampleNavTermSet(): START"); // Use the first TermStore object in the list. if (taxonomySession.TermStores.Count == 0) throw new InvalidOperationException("The Taxonomy Service is offline or missing."); TermStore termStore = taxonomySession.TermStores[0]; // Does the TermSet object already exist? TermSet existingTermSet = termStore.GetTermSet(TestConfig.NavTermSetId); if (existingTermSet != null) { Console.WriteLine(testContext, "RecreateSampleNavTermSet(): Deleting old TermSet"); existingTermSet.Delete(); termStore.CommitAll(); } Console.WriteLine(testContext, "RecreateSampleNavTermSet(): Creating new TermSet"); // Create a new TermSet object. Group siteCollectionGroup = termStore.GetSiteCollectionGroup(web.Site); TermSet termSet = siteCollectionGroup.CreateTermSet("Navigation Demo", TestConfig.NavTermSetId); NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, web, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider); navTermSet.IsNavigationTermSet = true; navTermSet.TargetUrlForChildTerms.Value = "~site/Pages/Topics/Topic.aspx"; NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink); term1.SimpleLinkUrl = "http://www.bing.com/"; NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl); NavigationTerm term2a = term2.CreateTerm("Term 2 A", NavigationLinkType.FriendlyUrl); NavigationTerm term2b = term2.CreateTerm("Term 2 B", NavigationLinkType.FriendlyUrl); NavigationTerm term3 = navTermSet.CreateTerm("Term 3", NavigationLinkType.FriendlyUrl); termStore.CommitAll(); Console.WriteLine(testContext, "RecreateSampleNavTermSet(): FINISH"); return navTermSet; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus