Anders G. Nordby

Lead Software Engineer at Sopra Steria

Monthly Archives: May 2014

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()) 

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

private static void DeletingCoursePage(SitePageData sitePageData)

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.