Wednesday, June 4, 2008

SharePoint ProcessBatchData Method for Batch Processing

Delete List Items using Batch Process, Instead of using SharePoint API. Normally we use listItem[index].Delete(); method to delete items one by one in list. But you can use "ProcessBatchData" method to delete the list items in the form of Batch Processing.

StringBuilder sb = new StringBuilder();
sb .Append("");
foreach (SPListItem item in CurrentList.Items)
{
sb.Append("");
sb.Append("" + CurrentList.ID + "");
sb.Append("" + item.ID.ToString() + "");
sb.Append("Delete");
sb.Append("
");
}
sb.Append("
");
try
{
SPContext.Current.Site.RootWeb.ProcessBatchData(sb.ToString());
}
catch (Exception ex)
{ throw ex; // Unable to delete}

No comments: