Tutorial :SharePoint List - Copy SPListItem ID


I have a solution that copies all the content of SharePoint lists to a file, and then copies the content of the file back onto SharePoint (used for backups and stage / live environment switches).

Now I can copy all the fields I need except for one : ID

I understand that it is a read only field, but some other read only fields can be updated (Created, Author, Modified, Editor, _ModerationStatus and _ModerationComments from what I have tested)

I can't use the CopyTo method because I cannot access the destination list.

I want to be able to keep the IDs because I don't want to break all the http://siteCollection//Lists/Posts/Post.aspx?ID=... URLs that appear all over the content of my website.

So basically, the system I have now (which pushes everything besides the ID) works well, as long as nothing gets deleted from the list. When something gets deleted (say ID = 1) the first item becomes ID=2 and when I push it in the empty destination list, it becomes ID=1.

Is there a way to force an ID for a SPListItem? It would almost definitely be a hack, but maybe someone has a way?



Well, if you just want that, why not create dummy item with ID=1 and then delete it? it should not be too difficult to add this logic


There might be something in the Content Deployment and Migration API to allow you do do this.

The first thing I would look at though is Gary Lapointe STSADM extensions as he's done some great work on extending the built in commands including imports that keep original GUID's intact.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »