标签:
在Sharepoint开发中可能需要一次删除成百上千条记录,这时候如果轮询SPList.Items并直接调用该对象的删除方法来删除的话性能极差,会叫你崩溃。
下面介绍一个快速删除大量数据的方法:
using (SPWeb myweb = mysite.AllWebs[“XXXX”]) { SPListItemCollection itemsCollection=CurrentList.Items; StringBuilder sbDelete = new StringBuilder(); sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>"); foreach (SPListItem item in itemsCollection) { sbDelete.Append("<Method>"); sbDelete.Append("<SetList Scope=\"Request\">" + CurrentList.ID + "</SetList>"); sbDelete.Append("<SetVar Name=\"ID\">" + Convert.ToString(item.ID) + "</SetVar>"); sbDelete.Append("<SetVar Name=\"Cmd\">Delete</SetVar>"); sbDelete.Append("</Method>"); } sbDelete.Append("</Batch>"); try { myweb.ProcessBatchData(sbDelete.ToString()); } catch (Exception ex) { Console.WriteLine("Delete failed: " + ex.Message); throw; } }
标签:
原文地址:http://www.cnblogs.com/ricky_li/p/4934579.html