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