Solution:
1. Construct a CAML query for each item in a list you want to delete
2. You can then pass on the aggregated CAML query for all the items to OOB ProcessBatchData() function as below:-
private static StringBuilder BuildBatchDeleteCommand(SPList list)
{
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("<?xml
version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string command
= "<Method><SetList
Scope=\"Request\">" +
list.ID +
"</SetList><SetVar
Name=\"ID\">{0}</SetVar><SetVar
Name=\"Cmd\">Delete</SetVar></Method>";
foreach (SPListItem item in list.Items)
{
sbDelete.Append(string.Format(command, item.ID.ToString())); }
sbDelete.Append("</Batch>");
return sbDelete;
}
string strBatchDelete =
BuildBatchDeleteCommand(list).ToString();
string strProcessBatch =
site.RootWeb.ProcessBatchData(strBatchDelete);This will place the items in a recycle bin. So to delete items from the recycle bin use
web.RecycleBin.Delete()
Refer to below form post to do it using powershell:-
http://sharepoint.stackexchange.com/questions/26542/deleting-all-the-items-from-a-large-list-in-sharepoint