Deleting a large number of items from a list in SharePoint
2008-09-26 22:56
465 查看
From :http://blog.thekid.me.uk/archive/2007/02/24/deleting-a-considerable-number-of-items-from-a-list-in-sharepoint.aspx
Recently the question was asked in the newsgroups about deleting a large number of items from SharePoint (WSS) in the fastest way. I had, in one if my projects, needed to remove a large number of item from SharePoint and the best way I found was to use 'ProcessBatchData' as it avoided the API and was considerably faster.
Here is some example code which will remove items from a SharePoint list. If you do this I would remember about the Recycle Bin and the effect deleting many items will have in the future...it maybe worth adding some code which also removes the items from the recycle bin once it has finished.
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
foreach (SPListItem item in CurrentList.Items)
{
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
{
SPContext.Current.Site.RootWeb.ProcessBatchData(sbDelete.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Delete failed: " + ex.Message);
throw;
}
I took me some time to re-find this code and so I have posted it here more for my benefit, but if anyone finds it useful then great.
Recently the question was asked in the newsgroups about deleting a large number of items from SharePoint (WSS) in the fastest way. I had, in one if my projects, needed to remove a large number of item from SharePoint and the best way I found was to use 'ProcessBatchData' as it avoided the API and was considerably faster.
Here is some example code which will remove items from a SharePoint list. If you do this I would remember about the Recycle Bin and the effect deleting many items will have in the future...it maybe worth adding some code which also removes the items from the recycle bin once it has finished.
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
foreach (SPListItem item in CurrentList.Items)
{
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
{
SPContext.Current.Site.RootWeb.ProcessBatchData(sbDelete.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Delete failed: " + ex.Message);
throw;
}
I took me some time to re-find this code and so I have posted it here more for my benefit, but if anyone finds it useful then great.
相关文章推荐
- How to delete a large number of data in SharePoint for List when refreshing data?
- How to delete a large number of data in SharePoint for List when refreshing data?
- Get List Status of workflow in sharepoint
- 转:How to submit the rows of a repeating table in InfoPath to a SharePoint list
- Writing CAML Queries from Retrieving List Items form SharePoint List
- sharepoint2010:The number of items in this list exceeds the list view threshold, which is 20000 items.
- Search List Items in SharePoint Portal Server
- 复制单链表成为新的链表,然后return the number of items in the new list
- Efficiently Delete / Purge All Items from a SharePoint List
- Rest Api how to retrieve list items from SharePoint Online
- ORA-01795: maximum number of expressions in a list
- Deleting large amounts of rows from SQL 2005 (2008) database tables
- UITableView 知识更新A table view displays a list of items in a single column. UITableView is a subclas
- Filter Lookup List in Sharepoint
- how to change folder's sort number in sharepoint?
- [转载]SharePoint List of Bloggers!
- compute exact number of triples of distinct elements in large array
- Fast Winding Number Inclusion of a Point in a Polygon
- ORA-01795: maximum number of expressions in a list is 1000 SQL异常
- sharepoint ECMA using a list template to creating a list in SubSIte