3

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

  • After adding the Item, get the list items and sort it with creation date and get the first time. – Vishwas Goswami Sep 24 '15 at 11:23
  • Maybe you find your answer here: sharepoint.stackexchange.com/questions/96493/… – Patrick Sep 24 '15 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# – Andre Morata Sep 24 '15 at 20:48
9

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 

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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