The base operation about Metadata Service in sharepoint 2013

本文详细介绍了如何将元数据从SharePoint 2010站点迁移到SharePoint 2013站点,并重点阐述了元数据服务的基本操作,包括获取服务、获取组、获取术语集等关键步骤。

This blog will continue The steps of migrating metadata from SP site 2010 to SP site 2013, and the below is about  The base operation about Metadata Service

public class ClientMetadataService
    {

        public List<string> getMetadaService(string siteUrl)
        {
            List<string> metadataServices = new List<string>();
            using (SPSite site = new SPSite(siteUrl))
            {
                TaxonomySession session = new TaxonomySession(site);
                TermStoreCollection termStores = session.TermStores;
                foreach (TermStore termStore in termStores)
                {
                    metadataServices.Add(termStore.Name.ToString());
                }
            }
            return metadataServices;
        }

        public List<string> getGroups(SPSite site, string metadataServiceName)
        {
            List<string> metadataGroups = new List<string>();
            try
            {
                TaxonomySession session = new TaxonomySession(site);
                TermStore termStore = session.TermStores[metadataServiceName];
                Microsoft.SharePoint.Taxonomy.GroupCollection groups = termStore.Groups;
                foreach (Microsoft.SharePoint.Taxonomy.Group group in groups)
                {
                    metadataGroups.Add(group.Name.ToString());
                }
            }
            catch { }
            return metadataGroups;
        }

        public List<string> getTermSets(SPSite site, string metadataServiceName, string groupName)
        {
            List<string> metadataTermSets = new List<string>();
            try
            {
                TaxonomySession session = new TaxonomySession(site);
                TermStore termStore = session.TermStores[metadataServiceName];
                Microsoft.SharePoint.Taxonomy.GroupCollection groups = termStore.Groups;
                Microsoft.SharePoint.Taxonomy.Group group = termStore.Groups[groupName];
                Microsoft.SharePoint.Taxonomy.TermSetCollection termSets = group.TermSets;
                foreach (TermSet termSet in termSets)
                {
                    metadataTermSets.Add(termSet.Name.ToString());
                }
            }
            catch { }

            return metadataTermSets;
        }

        public Term circleTerm(Term term, string termName)
        {
            Term newTerm;
            Term newTerm2;
            int termsCount = term.Terms.Count;
            if (term.Labels[0].Value == termName)
            {
                return term;
            }
            else if (termsCount > 0)
            {
                for (int i = 0; i < termsCount; i++)
                {
                    newTerm = term.Terms[i];
                    newTerm2 = circleTerm(newTerm, termName);
                    if (newTerm2 != null)
                    {
                        return newTerm2;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            return null;
        }

    }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值