SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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; 
share|improve this question
up vote 3 down vote accepted

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);
share|improve this answer
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. – Geir Smestad Sep 13 '11 at 12:22
This is not a good solution. It will break the Search Crawl!!! – Hristo Yankov Jan 15 '14 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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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