目前我有这个程序:
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();
}
}
}
有人可以告诉我如何确保从“第二阶段recyclebin / AdminRecyleBin”中删除所有项目,如导航到SharePoint中的此URL时所见:_layouts / AdminRecycleBin.aspx?View = 2
我在看方法时看到的是:
mySite.RecycleBin.MoveAllToSecondStage();
是否有类似“DeleteAllFromSecondStage();”的内容?
或者类似的东西:
mySite.RecycleBin.BinType = SPRecycleBinItemState.SecondStageRecycleBin;
答案 0 :(得分: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();
}
}
}