Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint 2013 - Taxonomy- Microsoft.SharePoint.Taxonomy.TaxonomySession.GetTaxonomySession”

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..

like image 772
Banng Avatar asked Apr 16 '14 09:04

Banng


People also ask

What is Sharepoint Taxonomy?

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.


2 Answers

credit to user1545314 and google

enter image description here

like image 139
Zakos Avatar answered Oct 11 '22 09:10

Zakos


  1. Go to the Managed Metadata service (in Service Applications in central admin).
  2. Select Managed Metadata Service Proxy (try clicking the empty space around the text rather than the text itself), and click Properties.
  3. Set that the application is default storage for keywords and for termsets.
like image 7
Christian Flem Avatar answered Oct 11 '22 08:10

Christian Flem