Question

I wish to move/cut a item from list in SharePoint to another list. I can copy the item across to a list and delete the original. Sadly version history is lost.

I want a way to be able to copy an item from one list to another and matain the history. I have thought about trying to use the SPExportObject and SPImportObject.

I have the following code to create a list item as an SPExportObject.

SPExportObject exportObject = new SPExportObject();
exportObject.Id = listItem.UniqueId;
exportObject.Type = SPDeploymentObjectType.ListItem;

I am not sure how I can now import exportObject into my other list.

Both lists are the same type.

Was it helpful?

Solution

SPExportObject/SPImportObject can be used to migrate the list item, but only issue that you need to take care is if you export an item from a database (e.g. a list) without exporting it's parent, then the exported item will become orphaned in the package. A package can contain multiple different orphaned objects (e.g. if you export multiple different lists or list items).

However, an import method allows us to define a new parent for each orphaned object in the export package. See this example for handling of parenting of list item: Using the Content Deployment APIs, ListItem are duplicated, when documents are not

It is important to remember, there are two important settings that are required to get this working:

WebUrl - this property defines the web that will be used as the new parent for all orphaned objects in the export package. This method (e.g.) cannot be used if the package contains orphaned documents as a web cannot be the parent of a document. The parent of a document needs to be a list or a folder.

RetainObjectIdentity - this defines whether to preserve the object identity during import or whether not to preserve the identity. If the value is false the objects will get a new generated Guid during import and it will be possible to assign a new parent to the imported orphaned objects.

Stefan from Microsoft has really good walkthfrough with Content Migration API

See Part 2 and Part 3 for more detailed insight

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top