views:

29

answers:

2

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?

Thanks!

+1  A: 

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

Vladi Gubler
I was hoping I would avoid doing something like that but I will go for that if it's my only option.
Hugo Migneron
Ended up going with that. Thanks!
Hugo Migneron
+1  A: 

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.

Ryan
Wow, I can't believe I had never heard of the content deployment and migration API. Will look into it and make some tests. At first sight, not sure it can do what I want to it, but it offers a lot of options for sure.
Hugo Migneron
Thanks for the suggestions. I managed to keep the GUIDs, fields, etc. Basically, everything but the IDs that I wanted to keep. The Content Deployment and Migration API didn't allow it either. I guess you just can't really force an identity field in a database... Ended up creating dummy items to fill the ID gaps.
Hugo Migneron
Thanks for updating - seems a glaring oversight!
Ryan