我正在使用 C# 更新管理元数据字段。以下是获取术语的 TermId 的代码。
string termId = string.Empty;
try
{
TaxonomySession tSession = TaxonomySession.GetTaxonomySession(CC);
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
TermSet tset = ts.GetTermSet(termSetId); // I have proper Guid here, checked this in SharePoint 2013 server.
LabelMatchInformation lmi = new LabelMatchInformation(CC);
lmi.Lcid = 1033;
lmi.TrimUnavailable = true;
lmi.TermLabel = "xyz"; //Name of the term.
TermCollection termMatches = tset.GetTerms(lmi);
CC.Load(tSession);
CC.Load(ts);
CC.Load(tset);
CC.Load(termMatches);
CC.ExecuteQuery();
if (termMatches != null && termMatches.Count() > 0)
termId = termMatches.First().Id.ToString();
}
catch (Exception ex)
{
var d = ex.Message;
}
return termId;
}
但我收到异常:“无法调用方法或从空对象检索属性。以下调用堆栈返回的对象为空。\"GetDefaultSiteCollectionTermStore\r\nMicrosoft.SharePoint.Taxonomy.TaxonomySession.GetTaxonomySession"。
我试图从 Sharepoint2013 手动加载,它在那里工作正常。有什么遗漏吗?感谢帮助..