Abhimanyu
Abhimanyu

Reputation: 423

how to restore items from recycle bin sharepoint programmatically?

Can records which are deleted from list can be restored other than administrator account? If possible how? In my current project, i have to give permissions for a group who are having "Approve" permission to restore the records which are deleted from the lists. Any suggestions?

Upvotes: 2

Views: 4803

Answers (2)

Dennis G
Dennis G

Reputation: 21788

Unfortunately there is no supported way to access the recycle bin for all items from a site collection as a non-site collection administrator.

The Recycle Bin only displays content deleted by the user who opens the Recycle Bin. So you will only see content in "your recycle bin" when you delete something yourself, even when you are a site owner. You will not be able to see documents deleted by someone else.

When being logged in as a site collection administrator you can open the recycle bin and see deleted items from all users. You even have the selection of views:

Upvotes: 1

Goyuix
Goyuix

Reputation: 24370

You will have to write some custom code to get around the security model - which if done correctly can have benefits in not granting excessive rights. Here is a code snippet to get you started:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
  using (SPSite site = new SPSite("http://server/"))
  {
    using (SPWeb web = site.OpenWeb())
    {
      if (web.RecycleBin.Count > 0)
      {
        web.RecycleBin[0].Restore();
      }
    }
  }
});

Upvotes: 1

Related Questions