TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Get all the Recycle Bin Items Using CSOM in SharePoint 2013 Online
Vijai Anand Ramalingam
May 16, 2016
25.4
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog you will see how to get all the recycle bin items using CSOM in SharePoint 2013 Online.
Code Snippet:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Security;
using
System.Text;
using
System.Threading.Tasks;
using
Microsoft.SharePoint.Client;
namespace
CSOMOffice365
{
class
Program
{
static
void
Main(
string
[] args)
{
string
userName =
"
[email protected]
"
;
Console.WriteLine(
"Enter your password."
);
SecureString password = GetPassword();
// ClienContext - Get the context for the SharePoint Online Site
// SharePoint site URL - https://c986.sharepoint.com
using
(var clientContext =
new
ClientContext(
"https://c986.sharepoint.com"
))
{
// SharePoint Online Credentials
clientContext.Credentials =
new
SharePointOnlineCredentials(userName, password);
// Get the SharePoint web
Web web = clientContext.Web;
// Get all the recycle bin items
// Reference: https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.client.recyclebinitem_members.aspx
RecycleBinItemCollection rbiColl = web.RecycleBin;
clientContext.Load(rbiColl);
// Execute the query to the server
clientContext.ExecuteQuery();
// Loop through each recycle bin item
foreach
(RecycleBinItem rbiItem
in
rbiColl)
{
Console.WriteLine(rbiItem.Title);
}
Console.ReadLine();
}
}
private
static
SecureString GetPassword()
{
ConsoleKeyInfo info;
//Get the user's password as a SecureString
SecureString securePassword =
new
SecureString();
do
{
info = Console.ReadKey(
true
);
if
(info.Key != ConsoleKey.Enter)
{
securePassword.AppendChar(info.KeyChar);
}
}
while
(info.Key != ConsoleKey.Enter);
return
securePassword;
}
}
}
Output: