How to copy Sharepoint list item to another list including list item versions

bklmnsh
bklmnsh used Ask the Experts™
on
Hello experts,

I'm copying sharepoint list item to another list using following code:

SPListItem newItem = destinationList.Items.Add();
newItem["ows_Title"] = sourceItem["ows_Title"];
....
newItem.Update();

What code do i need to add in order to copy list item versions as well?

Thanks for your help in advance!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

check the link below,

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx

see the method GetListItemVersionInformation on the page

Author

Commented:
krunal_shah, thank you for your prompt reply.
Your link provides information how to read list item version information, and this is quite trivial.
However I still need assistance how to copy versions information into new list item.
I'm not able to write newItem.Versions = sourceItem.Versions since Versions property is readonly, and there is no method in Versions collection allowing to add versions programatically.
Any help will be highly appreciated.
Jamie McAllisterCloud Expert
Most Valuable Expert 2013
Top Expert 2014

Commented:
This link details how to move list items. More digging would be required to move the prior versions too.

http://www.the-north.com/sharepoint/post/Propagating-Document-Library-Items-In-MOSS-Variations-(in-the-same-way-as-Pages).aspx

If not, I'm wondering if the Content Deployment API would do it for you?
Commented:
None of the above suggestions worked for me. Currently I'm just updating and item with data for each version so it contains all the modifications. Not very good solution but I'm not able to find better one.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial