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); }
public static NavigationTermSet CriarItemNaTermStore(string url, string urlweb, Guid NavTermSetId, Guid TaggingTermSetId) { SPSite site = new SPSite(url); SPWeb web = site.AllWebs[url]; TaxonomySession taxonomySession = new TaxonomySession(site); if (taxonomySession.TermStores.Count == 0) { throw new InvalidOperationException("O Serviço de taxonomia não existe"); } TermStore termStore = taxonomySession.TermStores[0]; TermSet existingTermSet = termStore.GetTermSet(NavTermSetId); if (existingTermSet != null) { existingTermSet.Delete(); termStore.CommitAll(); } Group siteCollectionGroup = termStore.GetSiteCollectionGroup(web.Site); TermSet termSet = siteCollectionGroup.CreateTermSet("Teste01", 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 = "https://ekisiot.sharepoint.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(); return(navTermSet); }
private NavigationTerm CreateSubTerm(NavigationTerm navTerm, string termTitle, string termURL) { NavigationTerm subTerm = navTerm.CreateTerm(termTitle, NavigationLinkType.SimpleLink); subTerm.SimpleLinkUrl = termURL; return navTerm; }
/// Creates a TermSet object for demonstration purposes. If it already exists, it will be deleted /// and then recreated. public static NavigationTermSet RecreateSampleNavTermSet( ClientContext clientContext, TaxonomySession taxonomySession, Web web) { clientContext.Load(taxonomySession, ts => ts.TermStores); clientContext.ExecuteQuery(); // 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]; clientContext.Load(termStore, ts => ts.Name, ts => ts.WorkingLanguage); // Does the TermSet object already exist? TermSet existingTermSet; clientContext.ExecuteQuery(); if (!existingTermSet.ServerObjectIsNull.Value) { existingTermSet.DeleteObject(); termStore.CommitAll(); clientContext.ExecuteQuery(); } // Create a new TermSet object. TermGroup siteCollectionGroup = termStore.GetSiteCollectionGroup(clientContext.Site, createIfMissing: true); TermSet termSet = siteCollectionGroup.CreateTermSet("Navigation Demo", TestConfig.NavTermSetId, termStore.WorkingLanguage); termStore.CommitAll(); clientContext.ExecuteQuery(); NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(clientContext, termSet, clientContext.Web, "GlobalNavigationTaxonomyProvider"); navTermSet.IsNavigationTermSet = true; navTermSet.TargetUrlForChildTerms.Value = "~site/Pages/Topics/Topic.aspx"; termStore.CommitAll(); clientContext.ExecuteQuery(); NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink, Guid.NewGuid()); term1.SimpleLinkUrl = "http://www.bing.com/"; NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl, Guid.NewGuid()); NavigationTerm term2a = term2.CreateTerm("Term 2 A", NavigationLinkType.FriendlyUrl, Guid.NewGuid()); NavigationTerm term2b = term2.CreateTerm("Term 2 B", NavigationLinkType.FriendlyUrl, Guid.NewGuid()); NavigationTerm term3 = navTermSet.CreateTerm("Term 3", NavigationLinkType.FriendlyUrl, Guid.NewGuid()); termStore.CommitAll(); clientContext.ExecuteQuery(); return(navTermSet); }