Articles about European Sharepoint Hosting Service
SharePoint Hosting – Restore Recycle Bin Items From SharePoint Site Using CSOM
A Recycle Bin is a temporary storage location for deleted items from that site.
When we delete an item first it goes to First Stage Recycle Bin and stays there for a short-term period then it moves to second-stage Recycle Bin.
In case of permanent deletion, we need to delete it again from second-stage Recycle Bin.
Sometimes we may require this item again in that case simply we need to restore it back from Recycle Bin. It can be restored by both manually and programmatically.
Here, I am going to explain how to Restore Recycle Bin Items from a SharePoint Site using Client Side Object Model (CSOM).
By using the below steps we can restore all items present in the Recycle Bin section.
Step 1
Retrieve Recycle Bin Items from the site.
Step 2
Restore it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SharePoint.Client; using System.Security; namespace RestoreRecyclebinSharepointItem { class Program { static void Main(string[] args) { SecureString pwd = new SecureString(); string Username ="testusera@demo.onmicrosoft.com"; string password = "Password"; try { using (ClientContext ctx = new ClientContext("https://portal.sharepoint.com/sites/Demosite")) { foreach (char c in password.ToArray()) pwd.AppendChar(c); ctx.Credentials = new SharePointOnlineCredentials(Username, pwd); RecycleBinItemCollection recycleBinItems = ctx.Site.RecycleBin; ctx.Load(recycleBinItems); ctx.ExecuteQuery(); //Restore all items from Recycle Bin recycleBinItems.RestoreAll(); ctx.ExecuteQuery(); Console.WriteLine("item restored"); } } catch (Exception ex) { } Console.ReadLine(); } } } |
Print article | This entry was posted by Peter on July 23, 2020 at 8:12 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |