SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a visual webpart which creates a list item, but I need to reference the newly created item's ID for later use in the same webpart. How would I do this in C#?


share|improve this question

The value of the ID is invalid after Add() and but instead created during Update(). See here.


SPList itemList = web.Lists["Animal Owner"];
SPListItem newOwner = itemList.Items.Add();
newOwner["Title"] = txtNewOwnerName.Text;

int newID = newOwner.ID; //Here I reference the ID from the newly created list item
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.