I have two lists that are using the same Managed Metadata column. I am attempting to copy this column when I create a new entry in one of the lists. My code looks like this:

        SPListItem li = site.RootWeb.Lists["UploadList"].AddItem();
        li["Title"] = workflowProperties.Item["Title"];
        li["TaxKeyword"] = (TaxonomyFieldValueCollection)workflowProperties.Item["TaxKeyword"]; 

For some reason when I look at the new list item that is created it never has a value for the "TaxKeyword" column. I have tried not casting it to TaxonomyFieldValueCollection and it still does not work... Any suggestions on how to do this?


When setting the value of Taxonomy Fields always use TaxonomyField.SetFieldValue

var sourceValue = sourceItem["SColumn"] as TaxonomyFieldValueCollection; 
var targetField = targetList.Fields["TColumn"] as TaxonomyField; 
targetField.SetFieldValue(targetItem, sourceValue);

Just setting targetItem["field"] doesn't update the hidden notes field or the hidden lookuplist


Use PopulateFromGuidValuePair method. Below is a snippet to set Managed Column value from another one.

TaxonomyFieldValueCollection sourceTaxVal = sourceItem["MMColumn"] as TaxonomyFieldValueCollection;
string taxVal = string.Empty;
foreach (TaxonomyFieldValue val in sourceTaxVal)
    taxVal += val.Label + "|" + val.TermGuid + ";";
 //taxVal = sourceItem["MMColumn"].ToString() //will also result in same value as above
 TaxonomyFieldValueCollection targetTaxVal = new TaxonomyFieldValueCollection(targetList.Fields["MMColumn"]);
 targetItem["MMColumn"] = targetTaxVal;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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