Quantcast
Channel: Sitecore Notes
Viewing all articles
Browse latest Browse all 3

Modify Bucket folder path format

0
0

Hello friends today we will see how to change the default bucket folder path format.

While understanding the architecture of current working project I found the bucket folder path structure is different then what actually Sitecore creating. This put me in a while and finally I found the way how Sitecore is creating it and how we changed it.

You must notice when you create Bucket item, it will automatically goes in to yyyy/MM/dd/HH/mm/ folder structure. This is default behavior and to check this setting you can find it in Sitecore.Buckets.config file under App_config\Include\ folder.

<settingname=”BucketConfiguration.BucketFolderPath”value=”yyyy\/MM\/dd\/HH\/mm”/>

For your reference I created one bucket item as shown in below screen capture.

Sitecore Bucket Structure1

Now you are thinking how to change this default behavior. Don’t worry we have the solution as explain below.

You can find below setting in Sitecore.Buckets.config file.

<settingname=”BucketConfiguration.DynamicBucketFolderPath”value=”Sitecore.Buckets.Util.DateBasedFolderPath, Sitecore.Buckets”/>

Now over next step is to write down different logic for Bucket folder path creation and call it instead of above setting.

Here to create different folder structure we will take first 3 characters of the created new bucket item. Below is the sample code.

using System;
using System.Globalization;
using Sitecore.Buckets.Util;
using Sitecore.Data;
using Sitecore.Diagnostics;

namespace Sitecore.Local.Bucketing
{
class BucketItemFolderPath : IDynamicBucketFolderPath
{
public BucketItemFolderPath() { }

public BucketItemFolderPath(Type t) { }

public string GetFolderPath(ID itemId, ID parentItemId, DateTime creationDateOfNewItem)
{
Assert.ArgumentNotNull(itemId, "itemId");
Assert.ArgumentNotNull(parentItemId, "parentItemId");

char[] path = IdHelper.NormalizeGuid(itemId).ToString(CultureInfo.InvariantCulture).Substring(0, 3).ToCharArray();
return string.Join(Sitecore.Buckets.Util.Constants.ContentPathSeperator, path);
}
}
}

Add one new file under \App_Config\Include\ folder like Bucket.DynamicBucketFolderPath.config and write below lines of code.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="BucketConfiguration.DynamicBucketFolderPath" patch:instead="setting[@name='BucketConfiguration.DynamicBucketFolderPath']"
value="Sitecore.Local.Bucketing.BucketItemFolderPath,Sitecore.Local.Bucketing "/>
</settings>
</sitecore>
</configuration>

That’s it. We are done. Build your solution and try to create new bucket items. You can see the new structure as shown in below screen capture.

Sitecore Bucket Structure2

Hope you enjoy this. Please feel free to give suggestions.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images