Programmatically deleting list items/documents with Recycle Bin support
Development, Inconvenient SharePoint, SharePoint, Tips & TricksIf you delete a document in SharePoint 2007 using the User Interface, it’s being moved to the Recycle Bin, so that it can be restored if necessary. There are situations when you want to include deleting list items and documents in your custom solutions. The most commonly used approach I’ve seen is calling the SPListItem.Delete() method. While this does the job, and deletes the item, it deletes it permanently instead of moving to the Recycle Bin.
Looking carefully at the SPListItem class, you can find the not-that-popular SPListItem.Recycle() method. Its description (Recycles the item and returns the item's GUID.
) is rather cryptic and doesn’t give you much clue on what you could use is for. It turns out that it’s exactly that method that you need to call in order to move a list item/document to the Recycle Bin instead of deleting it permanently.
In general moving items to the Recycle Bin instead deleting them permanently is what you should do in your custom solutions. It is standard SharePoint behavior and therefore something end users will expect of your solutions as well. You should perform the permanent deletion only if explicitly named in the requirements. Otherwise, let’s just stick to what SharePoint does to leverage the same User Experience.
Under the hood
Internally there isn’t much difference between the SPListItem.Delete and SPListItem.Recycle methods. Both call an internal SPListItem.Delete method with a different parameter which determines whether an item should be moved to the Recycle Bin or permanently deleted.

















March 20th, 2009 at 3:29 am
Thank you very much Waldek, it is exactly what I was looking for.
Marc
March 20th, 2009 at 8:46 am
@Marc Charmois: glad to help :)
April 7th, 2009 at 11:20 am
Thanks.Perfect one.
May 19th, 2009 at 1:08 pm
Hi,
Just wanted to know if the same will be applicable while deleting the versions in the document library.
I am using DocItem.File.Versions[i].Delete();
Will this send the fileversion to the recycle bin or will it directly delete the version from the site?
May 19th, 2009 at 1:24 pm
@vasudha: DocItem.File.Versions[i].Delete(); deletes the file permanently. It's hardcoded so you cannot change the default behavior.
May 19th, 2009 at 1:28 pm
Thanks for the reply Waldek.
My requirement is just that.
I want to delete the versions permanently and not to send them to recycle bin.
Just wanted to confirm on that one.
Thanks again.
October 1st, 2009 at 4:06 pm
Hi Waldek, thanks for the useful tip. How do you achieve the same thing using the Lists webservice UpdateListItems method? Passing in the CAML statement is simply the 'Delete' Cmd attribute value – how do you recycle via the UpdateListItems method?
October 1st, 2009 at 6:20 pm
@Dan Meineck: I haven't tried it with the WebServices yet, so it's definitely an interesting question whether it can be done at all. I will post here an answer if I find something more about it.
June 17th, 2011 at 8:14 am
gud post
January 4th, 2012 at 10:04 pm
Hi Waldek,
http://www.devexpertise.com/2009/02/04/deleting-list-items-in-a-sharepoint-list/
article says that if you use SPItem.Delete() gives error.
Collection was modified; enumeration operation may not execute.
So, Only the correct method is via SPitem.Delete[i].
Could you please check as the above mentioned article conflicts with yours?
Thanks
Khushi.