I am updating manage meta data field using C#. Following is code to get TermId for term.
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;
}
But I am getting exception as: “Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. \"GetDefaultSiteCollectionTermStore\r\nMicrosoft.SharePoint.Taxonomy.TaxonomySession.GetTaxonomySession”.
I have tried to load manually from Sharepoint2013, it works fine there. Is there anything missing ? Thanks for help..
A taxonomy is a formal classification system. A taxonomy groups the words, labels, and terms that describe something, and then arranges the groups into a hierarchy.
credit to user1545314 and google
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With