I have been reading about executing only one query after queuing up multiple items for processing in a SP list.
I have the following code where I have a button that loads in a bunch of records into an empty SP list from an Excel spreadsheet. If I do the executequery after every item.update it works ... but I think there should be a better way .. where I can queue up the items in an array maybe and send all items at once. I see examples on how to do that with exisitng list items...but I have not seen a way to do it with new items. I was able to do it with removing items...cache them all up and do one execute query to delete all items...and that is 1000 times faster than eq for each obviously. So looking to do the same with adding new items. Thanks for any ideas.
ER
private void buttonAddIndividualApplicants_Click(object sender, EventArgs e)
{
logThis("Start adding all individual applicants...");
//Set up SCOM
ClientContext context = new ClientContext(textBoxSPSite.Text);
List list = context.Web.Lists.GetByTitle(textBoxSPList.Text);
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = list.AddItem(itemCreateInfo);
//ListItemCollection items = new[];
//Set up Excel
var package = new ExcelPackage(new FileInfo(GlobalVars.ssFileName));
ExcelWorksheet workSheet = package.Workbook.Worksheets[GlobalVars.ssApplicantsTab];
//Start iterating through ss
for (int i = workSheet.Dimension.Start.Row + 1;
i <= workSheet.Dimension.End.Row;
i++)
{
logThis("Row:" + i);
string van = workSheet.Cells[i, 1].Value.ToString();
string appID = workSheet.Cells[i, 2].Value.ToString();
string name = workSheet.Cells[i, 3].Value.ToString();
string email = workSheet.Cells[i, 4].Value.ToString();
logThis(van + "-" + appID + "-" + name + "-" + email + " queued for processing.");
//Push an item to the stack:
oListItem["AppID"] = appID;
oListItem["ApplicantName"] = name;
oListItem["VAN"] = van;
oListItem["ApplicantEmailAddress"] = email;
oListItem.Update();
//context.ExecuteQuery(); ***with ExecuteQuery here it works
}
//After all items pushed onto stack...call ExQuery to apply
logThis("Starting ExecuteQuery to process queued list items...");
context.ExecuteQuery(); //Here it gives me only last name in spreadsheet
logThis("FINISHED ADDING INDIVIDUAL APPLICANTS");
}