Can anyone tell me how to create multiple SharePoint list items in batch using CSOM code.
I am referring to the batch creation using CSOM code to similar to the below code.. Below code is in server object model I want to achieve the same in CSOM..
region [ Method : Batch Add List item details ]
public void AddCanteenMenuDetails(string lstName, List<CanteenMenuDetails> objCanteenMenuDetails)
{
StringBuilder sbInsertCanteenMenu = new StringBuilder();
sbInsertCanteenMenu.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPList lstCanteenMenu = web.Lists.TryGetList(lstName);
bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
web.AllowUnsafeUpdates = true;
web.Update();
foreach (CanteenMenuDetails item in objCanteenMenuDetails)
{
sbInsertCanteenMenu.AppendFormat("<Method ID=\"{0}\">" +
"<SetList>{1}</SetList>" +
"<SetVar Name=\"ID\">New</SetVar>" +
"<SetVar Name=\"Cmd\">Save</SetVar>" +
"<SetVar Name=\"{3}Title\">{2}</SetVar>" +
"<SetVar Name=\"{3}Location\">{4}</SetVar>" +
"<SetVar Name=\"{3}WeekDays\">{5}</SetVar>" +
"</Method>", item.Title, lstCanteenMenu.ID, item.Title, "urn:schemas-microsoft-com:office:office#", item.LocationID, item.WeekDays);
}
sbInsertCanteenMenu.Append("</Batch>");
web.ProcessBatchData(sbInsertCanteenMenu.ToString());
web.AllowUnsafeUpdates = allowUnsafeUpdates;
web.Update();
}
}
}
#endregion