如何在C#中获取SharePoint术语的所有子项?

如何在C#中获取SharePoint术语的所有子项?,第1张

概述我正在为SharePoint 2010编写一个webpart,根据发布日期恢复某个(自定义)类型的最新页面.它仅考虑使用指定术语标记的页面.我希望它能够使用标记有所选术语的子项的页面来执行此 *** 作. 如果我有这样的术语树: >英格兰 >肯特 >多佛 >坎特伯雷 >萨里 >克罗伊登 >克劳利 然后通过选择肯特,我希望我的webpart显示标记为Kent,Dover或Canterbury的最新页面. 这 我正在为SharePoint 2010编写一个webpart,根据发布日期恢复某个(自定义)类型的最新页面.它仅考虑使用指定术语标记的页面.我希望它能够使用标记有所选术语的子项的页面来执行此 *** 作.

如果我有这样的术语树:

>英格兰

>肯特

>多佛
>坎特伯雷

>萨里

>克罗伊登
>克劳利

然后通过选择肯特,我希望我的webpart显示标记为Kent,Dover或Canterbury的最新页面.

这可能在C#中吗?

谢谢你的时间.

解决方法 您正在寻找的功能是 Term.GetTerms

您需要从您的字段中获取TaxonomyValue

然后,您必须获取当前的TaxonomySession,然后使用TaxonomySession获取字段中使用的术语.从该术语开始,您可以使用Parent字段获取父Term.
这里有一些粗略的代码向您展示所使用的对象.

TaxonomyFIEldValue v = null; // Notsurehowtodothisbit();        TaxonomySession session = new TaxonomySession(site);        if (session.TermStores != null && session.TermStores.Count > 0)        {            TermStore termStore = session.TermStores[0];            Term t = termStore.GetTerm(v.TermGuID);            Term parentTerm = t.Parent;               TermCollection childTerms = t.GetTerms();        }

获得树之后,您可以使用caml查询生成splist.GetList查询,该查询会返回标记为该方式的任何内容.

我没有在这方面做过实验……
但是Bart-Jan Hoeijmakers有

private splistItemCollection GetItemsByTerm(Term term,splist List)    {        // init some vars    splistItemCollection items = null;            SPSite site = SPContext.Current.Site;     // set up the TaxonomySession            TaxonomySession session = new TaxonomySession(site);        // get the default termstore    TermStore termStore = session.TermStores[0];           // If no wssID is found,the term is not used yet in the sitecollection,so no items exist using the term           int[] wssIDs = TaxonomyFIEld.GetWssIDsOfTerm(SPContext.Current.Site,termStore.ID,term.TermSet.ID,term.ID,false,1);        if (wssIDs.Length > 0)        {            // a TaxonomyFIEld is a lookupfIEld. Constructing the SPquery                   SPquery query = new SPquery();            query.query = String.Format("<Where><Eq><FIEldRef name='MyTaxonomyFIEld' LookupID='TRUE' /><Value Type='Lookup'>{0}</Value></Eq></Where>",wssIDs[0]);            items = List.GetItems(query);        }        return items;    }
总结

以上是内存溢出为你收集整理的如何在C#中获取SharePoint术语的所有子项?全部内容,希望文章能够帮你解决如何在C#中获取SharePoint术语的所有子项?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1246061.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存