SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I can empty the recycle bin for a site collection with the following:

public static bool EmptyRecycleBin(string siteCollection)
                using (var site = new SPSite(siteCollection))
                return true;
            catch (Exception ex)
                Console.WriteLine("Exception: {0}", ex);

                return false;

However this could cause issues and I'd like to only remove specific items (that I've deleted programatically) from here. Is there a way to do this or is it impossible?

share|improve this question
up vote 4 down vote accepted

You have to find the ID SPRecycleBinItem and use SPRecycleBinItemCollection.Delete or find the SPRecycleBinItem and use SPRecycleBinItem.Delete

This code deletes any instances of Test.png from the folder Test in the documentlibrary with rootfolder TestDocs from the recyclebin:

using (var site = new SPSite("http://sp2010"))
    var idsToDelete = new List<Guid>();
    foreach (SPRecycleBinItem item in site.RecycleBin)
        if (item.DirName.Equals("TestDocs/Test", StringComparison.OrdinalIgnoreCase)
         && item.LeafName.Equals("Test.png", StringComparison.OrdinalIgnoreCase))
share|improve this answer
How do I go about finding the ID if I only have the old filename? – Codingo Aug 30 '12 at 7:47
You have to loop through all the Items and check DirName and LeafName – Per Jakobsen Aug 30 '12 at 7:54
Could you provide an example? I'm having no success doing this – Codingo Sep 2 '12 at 23:19
Can't award the bounty for another six hours but this looks to work - thank-you! – Codingo Sep 3 '12 at 7:12
Example added to answer – Per Jakobsen Sep 3 '12 at 7:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.