Code Snippet:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Security;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.SharePoint.Client;
  9. namespace CSOMOffice365
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. string userName = "[email protected]";
  16. Console.WriteLine("Enter your password.");
  17. SecureString password = GetPassword();
  18. // ClienContext - Get the context for the SharePoint Online Site
  19. // SharePoint site URL - https://c986.sharepoint.com
  20. using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
  21. {
  22. // SharePoint Online Credentials
  23. clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
  24. // Get the SharePoint web
  25. Web web = clientContext.Web;
  26. // Get all the recycle bin items
  27. // Reference: https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.client.recyclebinitem_members.aspx
  28. RecycleBinItemCollection rbiColl = web.RecycleBin;
  29. clientContext.Load(rbiColl);
  30. // Execute the query to the server
  31. clientContext.ExecuteQuery();
  32. // Loop through each recycle bin item
  33. foreach (RecycleBinItem rbiItem in rbiColl)
  34. {
  35. Console.WriteLine(rbiItem.Title);
  36. }
  37. Console.ReadLine();
  38. }
  39. }
  40. private static SecureString GetPassword()
  41. {
  42. ConsoleKeyInfo info;
  43. //Get the user's password as a SecureString
  44. SecureString securePassword = new SecureString();
  45. do
  46. {
  47. info = Console.ReadKey(true);
  48. if (info.Key != ConsoleKey.Enter)
  49. {
  50. securePassword.AppendChar(info.KeyChar);
  51. }
  52. }
  53. while (info.Key != ConsoleKey.Enter);
  54. return securePassword;
  55. }
  56. }
  57. }
Output: