Plain and simple, I'm trying to delete a massive amount of items from a list as quickly as possible using a c# app, and have seen references to batch processes being the best way to do this. Not knowing much about them I've used examples online from places like this but keep running into the error <nativehr>0x80070057</nativehr><nativestack></nativestack>
when the application reaches the SPWeb.ProcessBatchData
step. Here is my code:
SPListItemCollection oCol = oList.Items;
StringBuilder sbDelete = new StringBuilder("<Batch>");
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"? >");
sbDelete.Append("<ows:Batch OnError=\"Return\">");
for (int x = oCol.Count - 1; x >= 0; x--)
{
sbDelete.Append("<Method>");
sbDelete.Append("<SetList Scope=\"Request\">" + oList.ID.ToString() + "</SetList>");
sbDelete.Append("<SetVar Name=\"ID\">" + oCol[x].ID.ToString() + "</SetVar>");
sbDelete.Append("<SetVar Name=\"Cmd\">Delete</SetVar>");
sbDelete.Append("</Method>");
}
sbDelete.Append("</ows:Batch>");
oWeb.AllowUnsafeUpdates = true;
oWeb.ProcessBatchData(sbDelete.ToString());
Can anyone spot what I'm doing wrong? I've tried multiple approaches recommended by sources like this and this but with no luck. The only theory I have is that the batch ends up being too big, but if so, what is the limit?