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);
            }
        }
示例#2
0
        private static void DeleteTermGroupImplementation(ClientContext cc, Microsoft.SharePoint.Client.Taxonomy.TermGroup termGroup, bool siteCollectionGroup = false)
        {
            if (termGroup.Name.StartsWith("TG_") || siteCollectionGroup)
            {
                foreach (var termSet in termGroup.TermSets)
                {
                    if (termSet.Name.StartsWith("TS_"))
                    {
                        foreach (var term in termSet.Terms)
                        {
                            // first deleted the reused terms to avoid issues with re-using the same term id in an upcoming test run
                            foreach (var reusedTerm in term.ReusedTerms)
                            {
                                term.DeleteObject();
                            }
                            cc.ExecuteQueryRetry();
                        }

                        termSet.DeleteObject();
                    }
                }

                if (!siteCollectionGroup)
                {
                    termGroup.DeleteObject();
                }
                cc.ExecuteQueryRetry();
            }
        }
示例#3
0
        // 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();
            }
        }
示例#4
0
        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();
        }