If you delete a document in SharePoint using the UI, it’s being moved to the Recycle Bin, so that it can be restored if necessary. There are situations when you want to include deleting list items and documents in your custom solutions. The most commonly used approach I’ve seen is calling the SPListItem.Delete() method. While this does the job, and deletes the item, it deletes it permanently instead of moving to the Recycle Bin.
Looking carefully at the SPListItem class, you can find SPListItem.Recycle() method. It turns out that it’s exactly that method that you need to call in order to move a list item/document to the Recycle Bin instead of deleting it permanently.
In general moving items to the Recycle Bin instead deleting them permanently is what you should do in our custom solutions. It is standard SharePoint behavior and therefore something end users will expect of our solutions as well. You should perform the permanent deletion only if explicitly named in the requirements. Otherwise, let’s just stick to what SharePoint does to leverage the same User Experience.
Internally there isn’t much difference between the SPListItem.Delete and SPListItem.Recycle methods. Both call an internal SPListItem.Delete method with a different parameter which determines whether an item should be moved to the Recycle Bin or permanently deleted.
Looking carefully at the SPListItem class, you can find SPListItem.Recycle() method. It turns out that it’s exactly that method that you need to call in order to move a list item/document to the Recycle Bin instead of deleting it permanently.
In general moving items to the Recycle Bin instead deleting them permanently is what you should do in our custom solutions. It is standard SharePoint behavior and therefore something end users will expect of our solutions as well. You should perform the permanent deletion only if explicitly named in the requirements. Otherwise, let’s just stick to what SharePoint does to leverage the same User Experience.
Internally there isn’t much difference between the SPListItem.Delete and SPListItem.Recycle methods. Both call an internal SPListItem.Delete method with a different parameter which determines whether an item should be moved to the Recycle Bin or permanently deleted.
- public override void Delete()
- {
- if (this.HasExternalDataSource)
- {
- SPUtility.ValidateFormDigest();
- string bdcid = (string) ((string) this.GetValue("BdcIdentity"));
- this.ParentList.DataSource.DeleteItem(bdcid);
- }
- else
- {
- this.DeleteCore(DeleteOp.Delete);
- }
- }
- public System.Guid Recycle()
- {
- if (this.HasExternalDataSource)
- {
- SPExternalList.ThrowNotSupportedExceptionForMethod("Recycle", base.GetType());
- }
- return this.DeleteCore(DeleteOp.Recycle);
- }
No comments :
Post a Comment