8

How can I get the ID of a list item that I just inserted in a list using the SP C# client library?

3
  • After adding the Item, get the list items and sort it with creation date and get the first time. Sep 24, 2015 at 11:23
  • Maybe you find your answer here: sharepoint.stackexchange.com/questions/96493/…
    – Patrick
    Sep 24, 2015 at 11:31
  • I see that using JSOM I can use the callback function to grab the ID of the recently inserted but I'm not seeing how to do that using C# Sep 24, 2015 at 20:48

1 Answer 1

18

You can refer below sample:

ClientContext context = new ClientContext("http://SiteUrl"); 
List listObj = context.Web.Lists.GetByTitle("ListName"); 
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); 
ListItem newItem = listObj.AddItem(itemCreateInfo); 
newItem["Title"] = "My New Item!"; 
newItem.Update(); 
context.Load(newItem);//Load the new item
context.ExecuteQuery();  
Console.WriteLine("ID of new item:{0}", newItem.Id);//Get ID 
1
  • It works! Thanks.
    – ZooZ
    May 29, 2019 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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