Anders G. Nordby

Senior Web Developer at CGI

Cleanup when Emptying Trash in EPiServer 7.x

The solution I’m currently working on has a lot of stuff in the Dynamic Data Store, this data relates to the various pages. So when the customer empties the trash bin, we want to take the opportunity to also clean out the “trash” from the DDS. During Application_Start() I have the following code:

private static Injected<IContentEvents> _contentEvents;

public static void Initialize()
{
    _contentEvents.Service.DeletingContent += EPiServerContentHandlers.DeletingContent;
}

internal static void DeletingContent(object sender, DeleteContentEventArgs e)
{
    if (e.DeletedDescendents == null || !e.DeletedDescendents.Any()) 
        return;

    var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
    foreach (var descendant in e.DeletedDescendents)
    {
        var page = contentRepository.Get<SitePageData>(descendant);
        DeletingCoursePage(page);
    }
}

private static void DeletingCoursePage(SitePageData sitePageData)
{
    PerformTheNecessaryCleanup();
}

Yes, pretty basic stuff, but we spent some time getting this to work correctly. Note that the EPiServer 6 event DeletingPage stil exists, but no longer works correctly in EPiServer 7.x.

Follow

Get every new post delivered to your Inbox.