Search This Blog

Monday, August 18, 2014

Bulk Deletion of Items from sharepoint list programmatically

static StringBuilder BuildBatchDeleteCommand(SPList spList) { StringBuilder sbDelete = new StringBuilder(); sbDelete.Append(""); string command = "" + spList.ID + "{0}Delete"; foreach (SPListItem item in spList.Items) { sbDelete.Append(string.Format(command, item.ID.ToString())); } sbDelete.Append(""); return sbDelete; } static void DeleteItems() { using (SPSite oSite = new SPSite("http://yh1002545lt")) { using (SPWeb oWeb = oSite.OpenWeb()) { SPListItemCollection spTktList = oWeb.Lists.TryGetList("ThreshHold").Items; SPListItem item = null; try { StringBuilder sb= BuildBatchDeleteCommand(oWeb.Lists.TryGetList("ThreshHold")); oWeb.ProcessBatchData(sb.ToString()); } catch (Exception ex) { } } } }