kamagra how much to take

Dump Recycle Bin Programmatically

At times, you may find that you wish to work with SharePoint recycle bins programmatically. I had a friend ask me this morning about approaches regarding dumping objects out of the recycle bin since he was experiencing storage issues disallowing deletion through the SharePoint web interface.

Working through the recycle bin through code is not a difficult task; there are a variety of object model pieces that you can use.

There are a few important ones:

SPRecycleBinItem – Represents an object in the Recycle Bin either at the site collection or site level

SPRecycleBinItemCollection – Represents a collection of SPRecycleBinItem objects

SPRecycleBinItemCollectionPosition – Represents the current page pointer of the recycle bin view

SPRecycleBinItemState – An enumeration containing the relevant SPRecycleBinItem object states, either FirstStageRecycleBin (site recycle bin) or SecondStageRecycleBin (site collection recycle bin)

SPRecycleBinItemType – An enumeration containing the SPRecycleBinItem object type, either:

Attachment
File
FileVersion
Folder
FolderWithLists
List
ListItem

SPRecycleBinOrderBy Specifies the piece of order data when executing a query against against the recycle bin.

SPRecycleBinQuery Specifies a query to run against the Recycle Bin in order to return SPRecycleBinItem objects

SPRecycleBinType An enumeration containing the type of the Recycle Bin, either:

RecycleBin
SiteRecycleBin

So, how we can we use these to start working with the Recycle Bin? Fortunately, there are a variety of methods that the SharePoint API provides you in order to do so. For example, let’s assume that you wanted to dump all the SPRecycleBinItem objects for a site so that the Recycle Bin was then empty. We can build an SPRecycleBinItemCollection by creating a new SPWeb object which contains the RecycleBin collection, which allows a variety of method access. One of these methods includes the DeleteAll() method.

  1. using (SPSite site = new SPSite(http://sharepointserver))
  2. {
  3. using (SPWeb web = site.OpenWeb())
  4. {
  5. try
  6. {
  7. web.RecycleBin.DeleteAll();
  8. }
  9. catch (Exception exception)
  10. {
  11.  
  12. }
  13.  
  14. }
  15. }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>