开发者

how to restore items from recycle bin sharepoint programmatically?

Can records which are deleted from list can be restored other than administrator account? If po开发者_开发百科ssible 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?


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();
      }
    }
  }
});


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:

  • End user Recycle bin items
    • this will show you the contents from all users' recycle bins
  • Deleted from end user recycle bin
    For programmatically restoring recycle bin items have a look at the SPRecycleBinItem.Restore Method. Or this tutorial on working with the recycle bin.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜