Tuesday 24 February 2009

EPiServer -- Deleted Pages


I was asked recently a few times how to detect deleted pages. Deleted from editors perspective, which means -- moved to the Recycle Bin. Answer to this question is really simple, PageData class has a property called IsDeleted, here is an example:

   1:  public static bool IsPageDeleted(PageReference pageRef)
   2:  {
   3:      PageData page = DataFactory.Instance.GetPage(pageRef);
   4:      return page.IsDeleted;
   5:  }

In fact, that is all what is needed to check if page was deleted. Below I would like to list additionally a few related tips which might be useful:
  • You can get reference to the Recycle Bin thanks to this static property:

       PageReference.WasteBasket
  • Another way to check if instance of PageReference class points to the Recycle Bin is to call this method:

       DataFactory.Instance.IsWastebasket(new PageReference(12))
  • If you would like to move a page to the Recycle Bin programmatically then you don't really want to delete the page, you should use this method instead:

       DataFactory.Instance.MoveToWastebasket(new PageReference(121));
  • EPiServer has by default scheduled job called "Automatic Emptying of Recycle Bin" which is responsible for:
    With Automatic Emptying of Recycle Bin, you can set how often your Recycle Bin should be emptied. The aim of this function is to stop old information from being left in the Recycle Bin for a long period of time. With automatic emptying, all information that is older than 30 days will be deleted from the Recycle Bin.

    So what can be wrong when pages from your Recycle Bin don't get removed? The most likely option is that this scheduled job is not activated, make sure that checkbox Active is checked ;)
If you need further details or some relevant information is missing then feel free to leave a comment.

Other interesting posts:

3 comments:

Steve C. said...

In R2, the GetPage method does not throw an exception if the page is deleted and you're not authenticated (which is a breaking change). If you use the multipage property or get a page id from some other storage, do a GetPage and show it, you could potentially show deleted information.

A worst case scenario for this is unintentional information exposure, as the editor expects a deleted page to be unavailable. It might still be available.

Make sure you test before you display.

AlanBarlow said...

Was looking for this for a long. Thanks for sharing.
custom logo

Haris said...

Thank you for sharing it with us.
I am really happy to see this blog.
It is very helpful for me.

Nursing assignment help