2009-07-16 34 views
0

目前我有這個程序:如何以編程方式從SharePoint 2007的第二階段回收站中刪除所有項目?

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(); 
     } 
    } 
} 

誰能告訴我怎樣才能確保這從「第2階段RECYCLEBIN/AdminRecyleBin」刪除所有項目,因爲當你瀏覽到這個網址在SharePoint中看到: _layouts/AdminRecycleBin.aspx查看= 2

我在看的方法看到的,是這樣的:?

mySite.RecycleBin.MoveAllToSecondStage(); 

有沒有類似 「DeleteAllFromSecondStage();」?

或許是這樣的:

mySite.RecycleBin.BinType = SPRecycleBinItemState.SecondStageRecycleBin; 

回答

2

我想通了,這裏是將刪除所有在SecondStageRecycleBin項目的代碼。

相關部分是「mySite.RecycleBin.BinType == SPRecycleBinType.SiteRecycleBin」以確定您要刪除SecondStageRecycleBin項目。

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(); 
     } 
    } 
} 
+0

沒錯。第二階段回收站位於網站集級別。 – 2009-07-17 11:29:57

相關問題