MSDN Archive Home
Help and FAQs
Efficiently Delete/Purge All items From A SharePoint List
All Resource Updates
Change History (all pages)
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
Feb 12 2008 at 2:12 PM
, version 4
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.
Sep 4 2009 at 3:28 PM
Thanks in advance for understanding,
Mar 26 2010 at 12:49 PM
in the example I had to change the code
to make it run!
May 3 2010 at 12:34 PM
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.
Jun 2 2010 at 8:57 AM
Thanks for posting this code. It's considerably speeded up my deletions.
Jan 7 2011 at 10:56 AM
The link to merill seems to be broken :-(
Sign in to add a comment
Mon Feb 4 2008 at 8:00 AM
More Tags ...
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.