• Publisert
  • 3 min

Create archive hierarchies in EPiServer

Replace EPiServer's archive job and organize expired content in a hierarchical structure based on published date.

After I published the Epinova QA checklist I've got a few questions on several of the checkpoints. One is how to avoid a large numbers of pages on the same level.

EPiServer's standard archive mechanism simply moves expired pages from one location to another. On "news driven" sites this will eventually result in a large number of pages at the same level. Which again leads to poor performance for editors. In the illustration below EPiServer would simply move expired pages from "News" to "News Archive" when archiving pages.

EPiServer default archive - large number of pages

The answer to this problem is the classic old-timer plugin Epinova.DateTreeArchive at CodeResort (now also available as NuGet).

Epinova.DateTreeArchive replaces the default archive job. It's configurable to create a subfolder hierarchy using a specified page type as item containers. The hierarchy in the example below is configured as "yyyy|MMMM".

(On a globalized site you would probably not use month names for subfolders, but it's possible as the module fully supports globalization.)

Epinova DateTreeArchive plugin with subfolder hierarchy

Configuration

The module is configured via Plugin Manager in admin mode.

Epinova DateTreeArchive configuration in Plugin Manager 1

Epinova DateTreeArchive configuration in Plugin Manager 2

These settings are global and will apply to all archives in the solution. But it's possible to create local deviations by using specific properties on your archive container:

Setting local archive format on container pages in Epinova.DateTreeArchive

The module is used on quite a number of sites and the combination of these settings are adequate in most scenarios. But there is still one more option available. For instance let's say you would like ordinal numbers on English content. To achieve this we'll use the format "yyyy|MMMM|dd" and write code for the ArchiveNameCreated event.

using System;

namespace Epinova.Research
{
    public class Global : EPiServer.Global
    {
        private static string[] OrdinalSuffix =
              { "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" };

        protected void Application_Start(Object sender, EventArgs e)
        {
            Epinova.DateTreeArchive.ArchiveJob.ArchiveNameCreated +=
                   ArchiveJob_ArchiveNameCreated;
        }

        void ArchiveJob_ArchiveNameCreated(DateTreeArchive.ArchiveEventArgs e)
        {
            if (e.DateFragment.Equals("dd") && e.LanguageBranch.Equals("en"))
            {
                var day = 0;
                if (Int32.TryParse(e.ArchiveName, out day))
                {
                    var msDigits = day % 100;
                    var lsDigit = day % 10;
                    int index = (msDigits >= 11 && msDigits <= 13) ? 0 : lsDigit;
                    e.ArchiveName =
                           string.Concat(e.ArchiveName, OrdinalSuffix[index]);
                }
            }
        }
    }
}

And the result looks like this

Using ordinal numbers on archive subfolders with Epinova.DateTreeArchive

Configuration option examples:

  • yyyy|MMMM - Year folder: "2012", month folder: "December"
  • yyyy|MMM - Year folder: "2012", month folder: "12"

Availability

The Epinova.DateTreeArchive plugin has been available for free from CodeResort for a while, but is now also available on the EPiServer NuGet feed.