//CSOM Assembly version - 16.1.4727.1200
//using Microsoft.SharePoint.Client
//GetFirstStageRecyclebinItems(credentials, weburl);
private static void GetFirstStageRecyclebinItems(SharePointOnlineCredentials credentials, string weburl)
{
RecycleBinItemCollection recyclebinItems = null;
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
Web oweb = ctx.Web;
//SP.Web.GetRecycleBinItems : retrieves the deleted items from the web site.
//Row Limit - 100 : Returns deleted items upto 100
//RecycleBinOrderBy.DefaultOrderBy - Order the items by default
//RecycleBinItemState.FirstStageRecycleBin - returns the items only from first stage
recyclebinItems = oweb.GetRecycleBinItems(null,100, false, RecycleBinOrderBy.DefaultOrderBy, RecycleBinItemState.FirstStageRecycleBin);
ctx.Load(recyclebinItems);
ctx.ExecuteQuery();
}
Console.WriteLine("Total deleted items:" + recyclebinItems.Count.ToString());
//RecycleBinItem.ItemType - Returns the type of the deleted object
//RecycleBinItem.LeafName - Returns the item name / file name of the object
foreach (RecycleBinItem item in recyclebinItems)
Console.WriteLine(item.ItemType + " - " + item.LeafName);
Console.WriteLine("Press any key to exit...");
Console.Read();
}This code snippet used to get the items from the RecycleBin (FirstStage) using CSOM.
