Friday, April 5, 2019

Get ID of an inserted list item via CSOM



// Get library columns collection.  
                        var libFields = list.Fields;
                        clientContext.Load(libFields);
                        clientContext.ExecuteQuery();

                        Microsoft.SharePoint.Client.File newFile = clientContext.Web.GetFileByServerRelativeUrl(fileUrl);
                        ListItem item1 = newFile.ListItemAllFields;
                        var fileN = fileName;
                        clientContext.Load(item1);//Load the new item
                        clientContext.ExecuteQuery();
                       // Console.WriteLine("ID of new item:{0}", newItem.Id);//Get ID 

item1.Id

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 

No comments:

Power Automate + Excel data

Extract excel data, get manager and update row with user details which will get from GET MANAGER Concepts and examples Key column:  Column i...