Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to copy a list item from one list to another. The lists are on the same site and the code is being fired inside of an item added/updated event receiver).

Both lists have managed metadata fields mapped to the same term sets.

Everything works as excepted until I try to set the Managed Metadata fields.

            SPListItem newItem = destinationList.Items.Add();
            newItem["Title"] = oldItem.Title;
            //Assign the rest of the non-taxonomy field values
            newItem.Update(); 
            SetTaxononmyField(newItem, myTaxonomyFieldValue, "fieldname");
            newItem.Update();

-

    private void SetTaxononmyField(SPListItem newItem, TaxonomyFieldValue value, string fieldname)
    {
        TaxonomyField field = newItem.Fields.GetFieldByInternalName(fieldname) as TaxonomyField;
        if (field != null)
        {
            field.SetFieldValue(newItem, value);//Throws "Specified method is not supported" exception here
        }
    }
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

The issue disappeared when I created a custom content type for the destination list. The code from above changes slightly to set the SPListItem content type.

            //retrieve and set the content type
            SPContentType contentType = destinationList.ContentTypes["ContentTypeName"];
            SPListItem newItem = destinationList.Items.Add();
            newItem["ContentTypeId"] = contentType.Id;
            newItem.Update();

If anyone could shed some light on why I had to do this I'd appreciate it.

share|improve this answer
add comment

I had the same problem today when copying. Difference for me I was copying from one column to another. Both columns were managed metadata columns pointing to the same managed metadata.

The reason I kept getting the error was because the column I read in was a Managed Metadata that allowed multiple values, the second column didn't. Therefore Specified Method was not supported because I was trying to add a TaxonomyFieldValueCollection to a column that only expected a TaxononomyFieldValue.

Looking at the code above, you might have been doing it the other way round. A TaxonomyFieldValue into a TaxonomyFieldValueCollection column.

share|improve this answer
add comment

Your Answer

 
discard

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.