Deleting a large number of items from a list in SharePoint

Source: Internet
Author: User

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 wowould remember about the recycle bin AND THE EFFECT deleting will change 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.