如何在sharepoint 2013中从NavigationTerm读取自定义属性值和术语描述?

时间:2015-05-12 09:08:20

标签: sharepoint sharepoint-2013

在发布sharepoint 2013网站时,我使用的是托管导航。我需要读取术语库中定义的自定义属性的值,我还需要读取描述字段的值。是否可以通过对网站的读取权限进行此操作?

我可以获得TaxonomyNavigationContext.Current.NavigationTerm并阅读基本信息。但是要阅读自定义属性和描述,我需要获得分类术语,我不能使用只读缓存导航术语。

TaxonomySession session = new TaxonomySession(site);
NavigationTerm navTerm = TaxonomyNavigationContext.Current.NavigationTerm;
Term term = navTerm.GetTaxonomyTerm(session); // I cannot do it due to permission level - user is read only user!
string val = term.CustomProperties["..."]; // this is what I need - read value of custom property - but without need to access Term class.

有没有办法如何从只读导航术语中读取自定义属性,并为用户分配了读取权限?

1 个答案:

答案 0 :(得分:0)

这项工作适用于seo属性,如果您调试可以看到属性,则可以获得CustomPropertiesLocalCustomProperties集合。

SPSite site = new SPSite(siteGuid);
SPWeb web = site.OpenWeb();

TaxonomySession session = new TaxonomySession(site);
NavigationTerm navTermino = TaxonomyNavigationContext.Current.NavigationTerm;
Term termino = navTermino.GetTaxonomyTerm(session);

//var seoTitle = termino.CustomProperties.Where(o => o.Key == "_Sys_Seo_PropBrowserTitle").SingleOrDefault();
var SEOPropBrowserTitle = termino.LocalCustomProperties.Where(o => o.Key == "_Sys_Seo_PropBrowserTitle").SingleOrDefault();
var SEOPropDescription = termino.LocalCustomProperties.Where(o => o.Key == "_Sys_Seo_PropDescription").SingleOrDefault();
var SEOPropKeyWords = termino.LocalCustomProperties.Where(o => o.Key == "_Sys_Seo_PropKeywords").SingleOrDefault();
var SEOPropSiteNoIndex = termino.LocalCustomProperties.Where(o => o.Key == "_Sys_Seo_PropSiteNoIndex").SingleOrDefault();