/ Published in: C#

This will delete all items in a SharePoint list. Better than looping through a SPListItemCollection and doing a .delete();
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SPList list = web.Lists[ListId]; SPListItemCollection splic = list.Items; batchString.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>"); foreach (SPListItem item in splic) { batchString.Append("<Method>"); batchString.Append("<SetList Scope=\"Request\">" + Convert.ToString(item.ParentList.ID) + "</SetList>"); batchString.Append("<SetVar Name=\"ID\">" + Convert.ToString(item.ID) + "</SetVar>"); batchString.Append("<SetVar Name=\"Cmd\">Delete</SetVar>"); batchString.Append("</Method>"); } batchString.Append("</Batch>"); SPContext.Current.Web.ProcessBatchData(batchString.ToString());
URL: http://msftplayground.com/archive/2009/03/16/bulk-deletion-of-splistitems-splistitemcollection.aspx
Comments
