Programmatically emptying the web and site Recycle Bins

I am currently working on a project, where I am migrating data from SQL into a SharePoint list. In doing so, I need to run this console utility through its paces, so, I have the need to constantly fill and purge the list several times.

Looping through each item within the list, for several thousand items is painstakingly slow however, so, I did find this great piece of code to do the job for me, which batch deletes all of the items from the specified list:

Works exactly as advertised, and will now forever sit in my SharePoint tool belt. However, this method moves those items into the Recycle Bin. So, I thought I would share this with everyone else…

To empty both the web and site recycle bins, run the following code (modified for your environment of course…)

   1: using (SPSite site = new SPSite(SPContext.Current.Site.ID))
   2: {
   3:     using (SPWeb web = site.OpenWeb("/"))
   4:     {
   5:         // empty the web recycle bin
   6:         web.RecycleBin.DeleteAll();
   8:         // empty the site collection recycle bin
   9:         site.RecycleBin.DeleteAll();
  10:     }
  11: }


About Geoff Varosky

Leave a Reply


You are commenting using your account. Log Out /  Change )

Google photo


Twitter picture


Facebook photo


Connecting to %s

%d bloggers like this: