public static void CreateTermSets(TokenParser _TokenParser, XElement _Branding, ClientContext clientContext, string termGroupName) { Console.WriteLine("Processing Term Sets . . . "); // This code assumes: // managed metadata service is running on the farm // default termstore exists for site collection // permission to managed metadata service have been granted // start a taxonomy session and connect to the Term Store TaxonomySession taxonomySession = TaxonomyExtensions.GetTaxonomySession(clientContext.Site); TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore(); // connect to Site Collection Terms (aka Term Group with Site Collection Name) Microsoft.SharePoint.Client.Taxonomy.TermGroup termGroup = termStore.GetTermGroupByName(termGroupName); //process each termset foreach (var termset in _Branding.GetDescendants("termsets", "termset")) { // fetch file path string termSetFilePath = termset.GetAttributeValue(_TokenParser, "termSetFilePath"); Console.WriteLine("Creating Term Set from contents of: {0}", termSetFilePath); // Create TermSet via File Import Microsoft.SharePoint.Client.Taxonomy.TermSet termSet = TaxonomyExtensions.ImportTermSet(termGroup, termSetFilePath); } }
public static void CreateProductTaxonomy(ClientContext ctx) { TermStore store = ctx.Site.GetDefaultKeywordsTermStore(); TermGroup productCategoryGroup = store.GetTermGroupByName("OD2"); if (productCategoryGroup == null) { productCategoryGroup = store.CreateTermGroup("OD2", Constants.TAXONOMY_OD2_GROUP_ID.ToGuid(), "Stuff for od2"); } TermSet ts = store.GetTermSet(Constants.TAXONOMY_PRODUCTCAT_TERMSET_ID.ToGuid()); ctx.Load(ts); ctx.ExecuteQuery(); // if term store does not exist create a new one. if (ts.ServerObjectIsNull.Value) { ts = productCategoryGroup.CreateTermSet("Product Category", Constants.TAXONOMY_PRODUCTCAT_TERMSET_ID.ToGuid(), 1033); store.CommitAll(); ctx.Load(ts); ctx.ExecuteQuery(); ts.CreateTerm("Prod Cat 1", 1033, Guid.NewGuid()); ts.CreateTerm("Prod Cat 2", 1033, Guid.NewGuid()); ts.CreateTerm("Prod Cat 3", 1033, Guid.NewGuid()); ts.CreateTerm("Prod Cat 4", 1033, Guid.NewGuid()); store.CommitAll(); ctx.ExecuteQuery(); } }
public static void CreateTaxonomyFavColor(ClientContext ctx) { TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore(); TermGroup group = store.GetTermGroupByName("School"); if (group == null) { group = store.CreateTermGroup("School", "{13E6924A-196D-4313-A1B4-3A21AF3958CF}".ToGuid(), "description"); } TermSet termSet = group.EnsureTermSet("Fav Color", "{3D4C7DE0-3867-44C3-871A-C36DEC4E1970}".ToGuid(), 1033); Term term = store.GetTerm("{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid()); ctx.Load(term); ctx.ExecuteQuery(); if (term.ServerObjectIsNull()) { termSet.CreateTerm("Green", 1033, "{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid()); termSet.CreateTerm("Blue", 1033, "{E96EF7E0-7F9B-4F66-BA1A-C2DBCC73DD78}".ToGuid()); termSet.CreateTerm("Red", 1033, "{13E22744-483D-49D2-B92D-6BD2E0C10D9C}".ToGuid()); ctx.ExecuteQuery(); } }
public static void CreateIssueCategoryTermSet(ClientContext ctx) { //TaxonomySession taxSession = TaxonomySession.GetTaxonomySession(ctx); //TermStore store = taxSession.TermStores[0]; TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore(); TermGroup group = store.GetTermGroupByName("OD1Test"); if (group == null) { group = store.CreateTermGroup("OD1Test", "{13E6924A-196D-4313-A1B4-3A21AF3958CF}".ToGuid(), "description"); } TermSet termSet = group.EnsureTermSet("Issue Category", "{3D4C7DE0-3867-44C3-871A-C36DEC4E1970}".ToGuid(), 1033); Term term = store.GetTerm("{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid()); ctx.Load(term); ctx.ExecuteQuery(); if (term == null) { termSet.CreateTerm("Just Right", 1033, "{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid()); termSet.CreateTerm("Low Priority", 1033, "{E96EF7E0-7F9B-4F66-BA1A-C2DBCC73DD78}".ToGuid()); termSet.CreateTerm("Urgent", 1033, "{13E22744-483D-49D2-B92D-6BD2E0C10D9C}".ToGuid()); ctx.ExecuteQuery(); } }
public static TermCollection GetTaxonomyTermSet(ClientContext ctx) { TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore(); TermGroup group = store.GetTermGroupByName("Luis"); TermSet termSet = group.TermSets.GetByName("Products"); TermCollection TermCollection = termSet.Terms; ctx.Load(TermCollection); ctx.ExecuteQuery(); return(TermCollection); }
public void GetTermSet(TaxonomyTypes taxonomyType, string termSetName, string groupName, bool createIfMissing, out TermStore termStore, out TermSet termSet) { termSet = null; Site site = _clientContext.Site; termStore = null; TaxonomySession session = TaxonomySession.GetTaxonomySession(_clientContext); switch (taxonomyType) { case TaxonomyTypes.SiteCollection: termStore = session.GetDefaultSiteCollectionTermStore(); break; case TaxonomyTypes.Keywords: termStore = session.GetDefaultKeywordsTermStore(); break; default: throw new Exception("Unexpected Taxonomytype"); } try { if (termStore != null) { _clientContext.Load(termStore); _clientContext.ExecuteQuery(); System.Threading.Thread.Sleep(1000); TermGroup termGroup = groupName == null ? termStore.GetSiteCollectionGroup(site, createIfMissing) : termStore.GetTermGroupByName(groupName); System.Threading.Thread.Sleep(1000); if (termGroup == null || termGroup.TermSets == null) { return; } _clientContext.Load(termGroup); _clientContext.Load(termGroup.TermSets); _clientContext.ExecuteQuery(); System.Threading.Thread.Sleep(1000); termSet = termGroup.TermSets.FirstOrDefault(ts => ts.Name == termSetName); } } catch (Exception ex) { throw; } }
// 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(); } }
static void CreateTerms(ClientContext ctx) { TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore(); Microsoft.SharePoint.Client.Taxonomy.TermGroup group = store.GetTermGroupByName("Tim"); if (group == null) { group = store.CreateTermGroup("Tim", "{9285FBFD-F1B1-44CA-ACFF-8CF4B271A5C2}".ToGuid()); } Microsoft.SharePoint.Client.Taxonomy.TermSet term = group.EnsureTermSet("Animals", "{FCB857B8-8F82-4EDD-B49A-5A5A5D492174}".ToGuid(), 1033); term.CreateTerm("Dog", 1033, "{E6251A5B-8341-4FC9-9544-30670C5E115B}".ToGuid()); Microsoft.SharePoint.Client.Taxonomy.Term cat = term.CreateTerm("Cat", 1033, "{F1D30452-0DD1-4B74-89CA-62167065BFF6}".ToGuid()); term.CreateTerm("Horse", 1033, "{25E73090-CFEF-4A83-997D-56FB127F0B82}".ToGuid()); ctx.ExecuteQuery(); cat.CreateLabel("Katt", 1053, false); cat.CreateLabel("Feline", 1033, false); ctx.ExecuteQuery(); }