Many times we require working with the Recycle bin of the web site in SharePoint. Here in this article I am going to discuss something interesting classes and their methods and properties for achieving this functionality in SharePoint.
First to start with, when we want to gain an access on recycle bin object at site or individual web level, then call RecycleBin property of SPWeb or SPSite object. This will give you SPRecycleBinItemCollection object.
Each item in SPRecycleBinItemCollection is SPRecycleBinItem. Let me explain you certain properties offered by SPRecycleBinItem object.
(1) Author – Gets the User who created the item.
(2) AuthorEmail - Gets the Email of the user who created this item.
(3) AuthorName – Gets the display name of the User who created this item.
(4) DeletedBy – Gets the User who deleted the item.
(5) DeletedByEMail – Gets the Email of user who deleted the item.
(6) DeletedByName – Gets the name of the use who deleted the item.
(7) DirName – Gets the relative URL of the list or folder which originally captained the item.
(8) ItemType – Gets type of an item deleted, what type of an item it was. It returns the SPRecycleBinItemType and it is enumeration which has following values.
Attachment : Specifies an attachment.
File :Specifies a file.
FileVersion: Specifies a file version.
Folder: Specifies a folder.
FolderWithLists: Specifies a folder that contains a list.
List :Specifies a list.
ListItem: Specifies a list item.
Remember one important thing. When you have child sites under your site collection, then when you delete any item it goes in to your web's recycle bin. When you delete an item from that recycle bin, it goes in to the site collection's recycle bin. so you can also get your deleted item from there.
These were certain properties of the class. Now I would like to highlight certain methods of the class.
(1) Delete: the item permanently from the recycle bin.
(2) MoveToSecondStage – this method moves the item from individual web’s recycle bin to the Site Collection recycle bin.
(3) Restore – As a name suggests, it restores the item to the original location.
Let us look into one more aspects of working with Recycle bin. We normally use SPQuery or SPSiteDataQuery to work with the queries from list and document library. But here to work with the Recycle bin, we will use SPRecycleBinQuery class.
SPRecycleBinQuery objQuery = new SPRecycleBinQuery();
objQuery.RowLimit = 100;
objQuery.OrderBy = SPRecycleBinOrderBy.Default;
SPRecycleBinItemCollection recycleitems = objWeb.GetRecycleBinItems(objQuery);
Now we have got the recycleitems, so you can iterate through them and can access properties and also work with methods.
That’s it.
5 comments:
very nice and informative
Very informative, I have question as to,
Is there any event which i can handle when an item is deleted or resotred from SiteRecycleBin by an admin, so that i can execute my custom business code.
Hi,
You have provided very good information on SharePoint Recycle Bin.
Is there way that we can query the Recycle bin using Webservices? If so, do you know how do we do that? Please let know
Thanks,
Vijay
Vijay,
very good question.
check this link-list of webservice
http://itfootprint.wordpress.com/2007/06/24/built-in-sharepoint-web-services-for-sharepoint/
and there are not any webservice for Recycle Bin items
we are still searching for your answer and we will definitely come back to you if found any clue.
Thanks,
Sharepoint kings
Hi,
Any further news on working with the recycle bin through the web services?
Thanks.
Post a Comment