views:

425

answers:

1

Currently I have this program:

namespace EmptySiteCollectionRecycleBin
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite mySite = new SPSite("http://mysharepointsite"))
            {
                try
                {
                    mySite.RecycleBin.DeleteAll();
                    if (mySite != null)
                    {
                        mySite.Dispose();
                    }
                }
                catch (Exception ex) 
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine("Recycle bin emptied");
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
    }
}

Can someone tell me how I can make sure that this remove all items from the "second stage recyclebin/AdminRecyleBin", as seen when you navigate to this url in SharePoint: _layouts/AdminRecycleBin.aspx?View=2

I see in looking at the methods, there is this:

mySite.RecycleBin.MoveAllToSecondStage();

Is there something like "DeleteAllFromSecondStage();"?

Or perhaps something like:

mySite.RecycleBin.BinType = SPRecycleBinItemState.SecondStageRecycleBin;
+1  A: 

I figured it out, here is the code that will delete all of the items in the SecondStageRecycleBin.

The pertinent portion is "mySite.RecycleBin.BinType == SPRecycleBinType.SiteRecycleBin" to determine that you are deleting the SecondStageRecycleBin items.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SharePointUtilities
{
    class EmptySiteCollectionRecycleBin
    {
        static void Main(string[] args)
        {
            #region SharePoint Delete RecycleBin Items
            using (SPSite mySite = new SPSite("http://mysharepointsite/"))
            {
                try
                {
                    //Empty the items from the SiteRecycleBin (the second stage recycle bin)    
                    if (mySite.RecycleBin.BinType == SPRecycleBinType.SiteRecycleBin)
                    {
                        int startCount = mySite.RecycleBin.Count;

                        //See the number of items before the delete
                        Console.Write("There are currently: " + startCount + " items in the Recycle Bin.\n");

                        //Delete all the items
                        mySite.RecycleBin.DeleteAll();

                        //See the number of items after the delete
                        Console.Write("\nThere are now: " + startCount + " items in the Recycle Bin, after deletion.\n");
                    }

                    //Make sure we dispose properly
                    if (mySite != null)
                    {
                        mySite.Dispose();
                    }
                }
                catch (Exception ex) 
                {
                    Console.WriteLine(ex.Message);
                }
            }
            #endregion
            Console.WriteLine("Recycle bin emptied");
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
    }
}
program247365
Right. The second stage recycle bin exists at the site collection level.
Alex Angas

related questions