I am trying to migrate a set of list columns to managed metadata columns. As part of this process, I have created a set of metadata columns parallel to the existing list columns, suffixed with the letter 'M'. I get references to the term store and term I wish to set, but when calling TaxonomyField.setFieldValue(), SharePoint hangs. The relevant parts of the code are given below. If this is relevant, this specific code is run through the debugger in the Page_Load event handler of an applciation page.

            SPList l = web.Lists["Testlib"];

            TaxonomySession oSession = new TaxonomySession(SPContext.Current.Site);
            TermStore oTermStore = oSession.TermStores["Metadata Service Application Proxy"];
            Group oGroup = oTermStore.Groups["Reports"];

            TermSet years = oGroup.TermSets["Year"];

            foreach (SPListItem i in l.Items)

                // If year non-null, move value from Year to YearM
                if (i["Year"] != null) {
                    string index = i["Year"].ToString();
                    Term thisYear= years.Terms[index];                        

                    TaxonomyField oField = (TaxonomyField)i.Fields["YearM"];

                    web.AllowUnsafeUpdates = true;
                    oField.SetFieldValue(i, thisYear); // Sharepoint hangs here
                    web.AllowUnsafeUpdates = false; 

2 Answers 2


You have to add a TaxonomyFieldValue in stead of a Term, something like this:

string termString = String.Concat(thisYear.GetDefaultLabel(1033), TaxonomyField.TaxonomyGuidLabelDelimiter, thisYear.Id);

TaxonomyFieldValue tagValue = new TaxonomyFieldValue(string.Empty);
oField.SetFieldValue(i, tagValue);
  • Thank you very much, this works. If this is relevant, I think I stumbled onto a weird bug in the process..when running my code, for some reason an "Updates not allowed over GET requests" exception pops up, regardless of whether I set the SPWeb to allow unsafe updates or not. This error does not happen when running your code. Sep 13, 2011 at 12:22
  • This is not a good solution. It will break the Search Crawl!!!
    – hyankov
    Jan 15, 2014 at 13:14

As noted by @Hristo Yankov you shouldn't set the string value directly as it may break the search index. Use the appropriate public APIs instead.

myTaxonomyField.SetFieldValue(myListItem, myTerm);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.