删除SharePoint列表中的所有项目

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了删除SharePoint列表中的所有项目相关的知识,希望对你有一定的参考价值。

This will delete all items in a SharePoint list. Better than looping through a SPListItemCollection and doing a .delete();
  1. SPList list = web.Lists[ListId];
  2. SPListItemCollection splic = list.Items;
  3. StringBuilder batchString = new StringBuilder();
  4. batchString.Append("<?xml version="1.0" encoding="UTF-8"?><Batch>");
  5.  
  6. foreach (SPListItem item in splic)
  7. {
  8. batchString.Append("<Method>");
  9. batchString.Append("<SetList Scope="Request">" + Convert.ToString(item.ParentList.ID) + "</SetList>");
  10. batchString.Append("<SetVar Name="ID">" + Convert.ToString(item.ID) + "</SetVar>");
  11. batchString.Append("<SetVar Name="Cmd">Delete</SetVar>");
  12. batchString.Append("</Method>");
  13. }
  14.  
  15. batchString.Append("</Batch>");
  16. SPContext.Current.Web.ProcessBatchData(batchString.ToString());

以上是关于删除SharePoint列表中的所有项目的主要内容,如果未能解决你的问题,请参考以下文章