Search Wiki:
Overview

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. Click on the Releases tab to download the solution.

If you'd like to just take a quick look at the code see http://www.merill.net/post/2008/02/Efficiently-Delete--Purge-All-Items-from-a-SharePoint-List.aspx
Last edited Feb 12 2008 at 2:12 PM  by merill, version 4
Comments
TOverby wrote  Apr 1 2008 at 2:03 PM  
I think this is a great way of doing this, however, I want to offer you another built-in option. In Sharepoint Server 2007, there is an option to open in Datasheet view. This allows you to select multiple items in the list and modify or delete them at the same time.

Glynn wrote  Sep 4 2009 at 3:28 PM  
Hi,

I'm terribly new at this, but is this something that can be run from within a script, i.e. in a Sharepoint webpart, like a javascript? I have an Access2007 client program connected to a remote SharePoint site and it takes FOREVER to delete all items in a SharePoint list... Is this something that has to be run from a .net client application? Can it run in VBA? Anyone?

Thanks in advance for understanding,

Glynnj

Knoerchen wrote  Mar 26 2010 at 12:49 PM  
Hi,

in the example I had to change the code

from spSite.RootWeb.ProcessBatchData(sbDelete.ToString());

to spSite.OpenWeb().ProcessBatchData(sbDelete.ToString());

to make it run!

Cheers!
Joerg

gunviro wrote  May 3 2010 at 12:34 PM  
Hi,

same thing happened to me as for Joerg. This is because the Website containing the List that I was willing to delete with this "Batch command" was not under the Root URL directory, thus "RootWeb" would not work for me either.

If you gave a subweb URL as the Site parameter make sure to use "spSite.OpenWeb()" to refer to the right Website.

Regards,
Gunviro.

pwmusic wrote  Jun 2 2010 at 8:57 AM  
Hi Merill

Thanks for posting this code. It's considerably speeded up my deletions.

Cheers

Patrick

steveculshaw wrote  Jan 7 2011 at 10:56 AM  
The link to merill seems to be broken :-(

Updating...
Page view tracker