Efficiently Delete / Purge All Items from a SharePoint List
2012-06-16 11:56
387 查看
If you want to delete or remove all the items in a SharePoint list you need to iterate through each item and perform a delete. Most of the examples on the web iterate through each item to do the delete. The problem there is that each delete action makes
a request to the server and a huge list is going to take a long time. You could always delete the entire list and recreate it but that would mean recreating the structure as well as the guid being changed.
The better method would be to make a single request with all the delete commands batched together as shown in the code sample below.
1: privatestatic StringBuilder BuildBatchDeleteCommand(SPList spList)
From: http://merill.net/2008/02/efficiently-delete-purge-all-items-from-a-sharepoint-list/
a request to the server and a huge list is going to take a long time. You could always delete the entire list and recreate it but that would mean recreating the structure as well as the guid being changed.
The better method would be to make a single request with all the delete commands batched together as shown in the code sample below.
1: privatestatic StringBuilder BuildBatchDeleteCommand(SPList spList)
2: {
3: StringBuilder sbDelete = new StringBuilder();
4: sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
5: string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
6: "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
7:
8: foreach (SPListItem item in spList.Items)
9: {
10: sbDelete.Append(string.Format(command, item.ID.ToString()));
11: }
12: sbDelete.Append("</Batch>");
13: return sbDelete;
14: }
From: http://merill.net/2008/02/efficiently-delete-purge-all-items-from-a-sharepoint-list/
相关文章推荐
- Writing CAML Queries from Retrieving List Items form SharePoint List
- Deleting a large number of items from a list in SharePoint
- Rest Api how to retrieve list items from SharePoint Online
- 使用SharePoint Web Serivce(2)--Update Delete a item in a list
- [msdn]Submitting Data from InfoPath 2007 to a SharePoint List
- How to delete a large number of data in SharePoint for List when refreshing data?
- SharePoint显示来自相同网站集另一个站点的列表 Display SharePoint list from another site
- Updating List Items with SharePoint Designer: 工作流没有启动
- How to delete a large number of data in SharePoint for List when refreshing data?
- SharePoint自动化系列——通过PowerShell创建SharePoint List Items
- Using SharePoint 2003 Web Services to Retrieve Data From A List
- Search List Items in SharePoint Portal Server
- Steps to Retrive Link List from SharePoint page
- MOSS2007 B2TR 下载,安装指南以及SDK下载(all from ms sharepoint team)
- sharepoint JQ获取List列表的值
- add a custom action to a SharePoint list actions menu for a specific list or content type
- Use Microsoft SharePoint Designer 2010 to customize the list view 2
- delete from PF_Annoy_Call_List
- Get all SharePoint database sizes
- SharePoint server 2016中文版导出list template,在另外一个环境不能显示