I have a list with about 500.000 thousand items. I need to delete all list items which created date is after a specific date.
The query would match about 450.000 thousand items. And then delete all of them.
Whats the fastest way to do it?
I have a list with about 500.000 thousand items. I need to delete all list items which created date is after a specific date.
The query would match about 450.000 thousand items. And then delete all of them.
Whats the fastest way to do it?
Here Is good code for this:
protected void Button1_Click(object sender, EventArgs e)
{
SPWeb witryna = SPContext.Current.Web;
SPList list = witryna.Lists["Szczegoly"];
StringBuilder sbDelete = BuildBatchDeleteCommand(list);
witryna.ProcessBatchData(sbDelete.ToString());
}
private static StringBuilder BuildBatchDeleteCommand(SPList spList)
{
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
"</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
foreach (SPListItem item in spList.Items)
{
sbDelete.Append(string.Format(command, item.ID.ToString()));
}
sbDelete.Append("</Batch>");
return sbDelete;
}
Another option would be connecting to the list via Access and running a delete query against the list.
You can write a small jQuery-snippet with SPServices, This forum post seems to work, so just change the listname and the CAML Query according to your criteria.