コード例 #1
0
        private void GetTaxonomyFieldInfo(ClientContext clientContext, out Guid termStoreId, out Guid termSetId)
        {
            TaxonomySession   session   = TaxonomySession.GetTaxonomySession(clientContext);
            TermStore         termStore = session.GetDefaultSiteCollectionTermStore();
            TermSetCollection termSets  = termStore.GetTermSetsByName("Department", 1033);

            clientContext.Load(termSets, tsc => tsc.Include(ts => ts.Id));
            clientContext.Load(termStore);
            clientContext.ExecuteQuery();
            termStoreId = termStore.Id;
            termSetId   = termSets.FirstOrDefault().Id;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: vsuryana/Testing
        static void GetTaxonomyFieldInfo(ClientContext clientContext, string TermsetName, out Guid termStoreId, out Guid termSetId)
        {
            termStoreId = Guid.Empty;
            termSetId   = Guid.Empty;
            TaxonomySession   session   = TaxonomySession.GetTaxonomySession(clientContext);
            TermStore         termStore = session.GetDefaultSiteCollectionTermStore();
            TermSetCollection termSets  = termStore.GetTermSetsByName(TermsetName, 1033);

            clientContext.Load(termSets, tsc => tsc.Include(ts => ts.Id));
            clientContext.Load(termStore, ts => ts.Id);
            clientContext.ExecuteQuery();
            termStoreId = termStore.Id;
            termSetId   = termSets.FirstOrDefault().Id;
        }
コード例 #3
0
        /// <summary>
        /// Returns Taxonomy store and set details
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="logger"></param>
        /// <param name="termSetName"></param>
        /// <param name="cultureId"></param>
        /// <returns>NULL if an Exception is thrown</returns>
        public static SPOTaxonomyModel GetTaxonomyFieldInfo(this ClientContext clientContext, ITraceLogger logger, string termSetName, int cultureId = 1033)
        {
            TaxonomySession   session   = TaxonomySession.GetTaxonomySession(clientContext);
            TermStore         termStore = session.GetDefaultSiteCollectionTermStore();
            TermSetCollection termSets  = termStore.GetTermSetsByName(termSetName, cultureId);

            SPOTaxonomyTermSetModel   modelTermSet   = null;
            SPOTaxonomyTermStoreModel modelTermStore = null;

            try
            {
                clientContext.Load(termSets,
                                   tsc => tsc.Include(
                                       tctx => tctx.Id,
                                       tctx => tctx.CustomSortOrder,
                                       tctx => tctx.IsAvailableForTagging,
                                       tctx => tctx.Owner,
                                       tctx => tctx.CreatedDate,
                                       tctx => tctx.LastModifiedDate,
                                       tctx => tctx.Name,
                                       tctx => tctx.Description,
                                       tctx => tctx.TermStore,
                                       tctx => tctx.Group,
                                       tctx => tctx.IsOpenForTermCreation));

                clientContext.Load(termStore,
                                   tctx => tctx.Id,
                                   tctx => tctx.Name,
                                   tctx => tctx.IsOnline,
                                   tctx => tctx.DefaultLanguage,
                                   tctx => tctx.ContentTypePublishingHub,
                                   tctx => tctx.WorkingLanguage);
                clientContext.ExecuteQueryRetry();

                modelTermStore = new SPOTaxonomyTermStoreModel()
                {
                    Id                       = termStore.Id,
                    Name                     = termStore.Name,
                    IsOnline                 = termStore.IsOnline,
                    DefaultLanguage          = termStore.DefaultLanguage,
                    ContentTypePublishingHub = termStore.ContentTypePublishingHub,
                    WorkingLanguage          = termStore.WorkingLanguage
                };

                TermSet termSet = termSets.FirstOrDefault();
                modelTermSet = new SPOTaxonomyTermSetModel()
                {
                    Id = termSet.Id,
                    IsAvailableForTagging = termSet.IsAvailableForTagging,
                    IsOpenForTermCreation = termSet.IsOpenForTermCreation,
                    CustomSortOrder       = termSet.CustomSortOrder,
                    Owner            = termSet.Owner,
                    CreatedDate      = termSet.CreatedDate,
                    LastModifiedDate = termSet.LastModifiedDate,
                    Name             = termSet.Name,
                    Description      = termSet.Description
                };

                if (termSet.TermStore != null &&
                    termSet.TermStore.Id != null)
                {
                    var tempStore = termSet.TermStore;
                    modelTermSet.TermStoreId = tempStore.Id;
                }

                if (termSet.Group != null)
                {
                    var termGroup = termSet.Group;
                    modelTermSet.Group = new SPOTaxonomyItemModel()
                    {
                        Id               = termGroup.Id,
                        Name             = termGroup.Name,
                        CreatedDate      = termGroup.CreatedDate,
                        LastModifiedDate = termGroup.LastModifiedDate
                    };
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Failed to retreive TermStore session {0} with message {1}", termSetName, ex.Message);
                return(null);
            }

            // Build model
            var termsetModel = new SPOTaxonomyModel()
            {
                TermSetName = termSetName,
                TermStore   = modelTermStore,
                TermSet     = modelTermSet
            };

            return(termsetModel);
        }