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 GoswamiSep 24, 2015 at 11:23
-
Maybe you find your answer here: sharepoint.stackexchange.com/questions/96493/…– PatrickSep 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#– Andre MorataSep 24, 2015 at 20:48
Add a comment
|
1 Answer
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