Sharepoint content deployment API can be used for copying various content between different environments. You can choose what content you need to copy:
- List item
Appropriate values are determined in SPDeploymentObjectType enumeration. If you export/import separate list items from Sharepoint lists or files (files represent pages/documents/images, i.e. content inside document libraries) then you may face with situation when you need to export managed metadata applied to this content. In this post I will share several aspects of the copying managed metadata with content deployment API.
For testing we will use simple Languages term set with several terms:
Also we will need 2 site collections: source and target for content deployment.
Lets start from lists items. Create custom list on the source site collection and add managed metadata column Language which is bound to the term set which we created above. Then create new list item:
We need also to create similar custom list on the target site collection with the same title (and same Url – it is important that Url will be the same. Otherwise we would need to re-parent content during importing).
Now we will import created single list item using the following code:
And the following code for importing:
Note that as I said you need to remember that we use the same Urls for lists so we can import content without re-parenting. Otherwise you will need to add code which re-parent objects during import. Example can be checked here.
Lets check what we will have on target site collection when this code will be ran:
Managed metadata values were copied, but there is number of side effects:
- Hidden Note field which is used internally by Sharepoint for each managed metadata field became visible
- Taxonomy Catch All Column field became visible
The most serious problem is that imported field is not updatable, i.e. if you will try to add e.g. Swedish language and save list item, when you will re-open item in edit form you will still see 3 imported values (English, Finnish, Russian).
Also in default list view imported values won’t be shown:
It happens because Sharepoint created new Language field, i.e. now there are 2 Language fields in the list on the target site collection. You can check it in List settings:
It will work by the same way if you will add some OTB managed metadata field, e.g. Enterprise Keywords, except that duplicated field won’t be created.
For pages the picture is the same. Code for exporting will be slightly different:
After importing on the target there also will be additional fields in page metadata. Also values in managed metadata fields may be not copied as well:
I found workaround for the 2 mentioned problems: non-updatable fields on the target and showing of the Taxonomy Catch All Column. In our tests we used fields. If you will use content type with managed metadata fields, bind it to the pages doclib (on both site collections) and then run export/import – Sharepoint will also make Note fields visible. However Taxonomy Catch All Column won’t be shown. Also it will be possible to update values in the managed metadata fields on the target.
It is possible to hide Note field from content type on target site collection. However it will become visible on the next import again. I.e. you will need to hide Note fields after each import operation.
That’s all observations which I would like to share here. If there will be more information in the future I will update this post.