In our previous write-up we chatted about report templates in general as well as how to create them. I wanted to spend a few minutes (as promised) to show you how to use your own templates within your applications as a means to assist end users to get up and running with internal reporting. Oftentimes companies have the same stylistic and structural elements across their large set of reports. In other words, when someone tells me they have hundreds of reports they really have a smaller set of “base” reports that contain a certain aesthetic and structure to them. Whenever your end users want to create a new Product report, for example, what they really mean is that they want to create a variation on an existing product report. When end users are confronted with a blank report they will often use the developers as a safety valve to help them get started. Instead of constantly facing that endless time sink-hole, why not present them with a dialog that has your basic reports and let the users chose from that set.
How hard is this to do then? It is truly quite simple and can be accomplished in two simple steps:
- Create a report template extension by inheriting from the ReportTemplateExtension class
- Register the extension
Once these two steps are complete, your custom end user report designer will show the “Load Report Template” link that…
The first step mentioned was creating a descendant of the ReportTemplateExtension abstract class. This is implemented by overriding the GetTemplates( ) function. You are truly free to retrieve the templates from whatever storage medium you see fit. In this instance I simply have all of the templates tucked away into a Templates folder.
public class CustomTemplate : ReportTemplateExtension
public override IEnumerable<Template> GetTemplates()
var archive = new TemplateArchiveManager();
string path = Path.Combine(Application.StartupPath, "Templates");
var files = Directory.GetFiles(path);
var templates = new List<Template>(files.Length);
foreach (string file in files)
using (Stream stream = new MemoryStream(File.ReadAllBytes(file)))
The second step was to register the extension with the reporting system. This is easily done with the following line of code:
This should be done when the application first starts.
That should do it! In two simple steps we can now enable our end users to quickly and easily get started with reports with custom templates. I would love to see how this feature is used!
As always, if there are any comments and/or questions, feel free to get a hold of me!
Want The Best Reporting Tool Ever?
Get The No-Compromise Reporting Tool for WinForms, ASP.NET, Silverlight and WPF! - Native integration with DevExpress WinForms and ASP.NET Controls, unequalled design-time productivity, industrial-grade features. Try a fully-functional version of DXperience for free now: http://www.devexpress.com/Downloads/NET/
Let us know what you think of our Reporting Suite by rating it in the VS Gallery!