Sitecore Item Buckets with meaningful folder paths

Organizing items using buckets is one of the most useful features of Sitecore 7. The ability to quickly bucket and un-bucket sections makes it an even more attractive feature.

One drawback however, is that out of the box it only creates folder paths based on an item’s creation date. This isn’t helpful in scenarios where the item’s creation date is different from the content date, such as news articles created in advance for future publication.

To solve this problem, I decided to extend the bucket folder creation method and add configuration that lets you specify a date field for every template.

Here’s how to do this -

Step 1: First, create a bucket configuration and add it to a Settings file

GetFolderPath method uses the custom BucketFolderConfigurationManager class created in Step 2 that reads the field names for templates from the configuration.

If the field name is not specified or if the item does not have that date field it defaults to creation date of the new item.

Step 4: The code above will take care of correctly organizing the items when bucket-sync command is executed. However, this still does not solve the problem of moving items to the correct folder based on item creation dates because when the item is first created it does not have the date field filled in. To solve this, we’ll add a new item saved event handler.