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.

  • Are the two lists existing in two different Site Collections or Content Databases, or the same site collections? – Falak Mahmood Jun 29 '12 at 18:25
  • Same site collection. – John Jun 29 '12 at 20:47
  • My reponse applies to same site collection. Hope it helps. – Falak Mahmood Jun 29 '12 at 20:50

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

  • Do you always need to export to disk then import from it? – John Jun 29 '12 at 20:52
  • Yes, file location property must be define for Import/Export. – Falak Mahmood Jun 29 '12 at 20:58

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.