views:

2925

answers:

3

I need to create list items in sharepoint and also set the ID field too. However I get an error when trying to do this as it's read only. Is there a way I can set the ID column value when programmatically creating items in a sharepoint list?

As a side note the reason I need to do this is because I need to add items to two sharepoint lists where the second uses the id column of the first as a lookup.

thanks

Kamran

+3  A: 

As you already mentioned, the ID of a list item is marked as read only. And I think there is no way to work around that.

I think the easiest solution would be to add a new column to the second list which uses the first ID column for lookup. Then the items in list one and two still have two different IDs but you can reference them by the second column in list two.

Flo
+1  A: 

Flo, beat me to the punch. I was about to recommend the same thing. The ID you probably want to save in the new column will be UniquID property of the spListItem property. This is the GUID associated with that item.

Scott Price
I was suspecting that I would have to do the same, just wanted to be sure I'm not missing anything obvious.Thanks for answering.
Kamran
A: 

Hi, I think the best idea is Flo's one, but using Features you can add items and set their id. So, if a feature can do why don't we?

jaloplo