In this blog I will explain how to add a button to the content editor and download data as an CSV file. For this example I will assume that we want to download the data for a given web form for marketers form as a CSV file.
Adding the button
You may not have noticed but this is a contextual ribbon that is it is only shown when the item is based on the forms template, as it gives no meaning to have the download data as CSV added to all items.
First you need to swap to the core database, and navigate to the Contextual Ribbons item for the content editor i.e. /sitecore/content/Applications/Content Editor/Ribbons/Contextual Ribbons.
This is where all the ribbons that are only shown for specific item types are placed; within this folder there is a forms toolbar, which contains a form strip, which contains a forms chunk, which in turn contains the “Export Data as CSV” button item.
The most important part of the button item is the click field, which defines the command name that will be raised when the button is clicked (I will explain how to hook this up in more detail later).
But how is a contextual ribbon associated with a given template – well that part is easy on the template item under the appearance section there is a ribbon field which can define a contextual ribbon or toolbar to be shown.
How to hook the button click up to the code that is to executed?
We have to add a command item to the /app_config/commands.config file to bind the command name to the class that is going to provide the functionality.
<command name="forms:exportformdata" type="WFFM.SQLServer.SaveToDatabase.Infrastructure.Commands.ExportFormDataCommand, WFFM.SQLServer.SaveToDatabase" />
The class must inherit from the Sitecore Command class, and override the Execute function.
internal class ExportFormDataCommand : Command
public override void Execute(CommandContext context)
Assert.IsNotNull(context.Items, "context items are null");
Assert.IsTrue(context.Items.Length > 0, "context items length is 0");
Item contextItem = context.Items;
Assert.IsNotNull(contextItem, "First context item is null");
private void OpenNewWindow(ID id, string name)
UrlString url = new UrlString(Constants.Url.ExportFromDataPage);
The aspx page doesn’t do that much it just sets the ContentType to “text/csv” and streams the data. If you want to see the complete implementation, you can download it from github
Hope this was helpful, Alan