Bulk Delete a large number of entries in SharePoint

Source: Internet
Author: User

You may need to delete hundreds or thousands of records at one time in SharePoint development, and if you poll Splist.items and call the Delete method of the object directly to remove it, the performance is very poor and will cause you to crash.

Here's a quick way to delete large amounts of data:

using(SPWeb myweb = MySite. allwebs["XXXX"]) {splistitemcollection itemscollection=currentlist.items; StringBuilder Sbdelete =NewStringBuilder (); Sbdelete.append ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "?><batch> ");foreach(SPListItem IteminchItemsCollection) {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{MyWeb. Processbatchdata (Sbdelete.tostring ()); }Catch(Exception ex) {Console.WriteLine ("Delete failed:"+ ex. Message);Throw; }}

Bulk Delete a large number of entries in SharePoint

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.