New to Telerik Reporting? Download free 30-day trial

How to implement a report definition storage

This article describes how to use the Web Report Designer to design reports that are stored in a custom storage location.

Overview

Out-of-the-box we provide a FileDefinitionStorage that is configured to use the file system. To open reports stored differently, you need to implement the IDefinitionStorage interface. This will enable the web designer to load reports from a custom location, such as a database, cloud, in-memory, etc.

The Web Report Designer previews the reports in Html5 Report Viewer. The latter utilizes a Telerik Reporting REST Service to render the reports. The client-side reportSource sent by the web designer is resolved to a server-side ReportSource by the Resolve method of the Reporting REST Service ReportSource Resolver. The ReportSource resolver is supposed to read report definitions created with the web report designer. For that reason, in the most of the cases when creating custom IDefinitionStorage it will be necessary to create also a custom ReportSource resolver that is able to read the report definitions from the storage and return them as valid server-side ReportSources.

The byte[] returned by the GetDefinition method of the IDefinitionStorage will be processed by the virtual GetReport method of the ReportDesignerController. The default implementation of the GetReport method utilizes the definitionId s returned by the ListDefinitions method of the IDefinitionStorage to identify the type of the report definition in the byte[]. If the definitionId contains the extension '.trdp', the report will be treated as a TRDP package. Otherwise, the byte[] is regarded as an XML report definition, i.e. a TRDX report. For that reason, by default, if the GetDefinition method returns a report definition packed with the ReportPackager, the corresponding definitionId must finish with the '.trdp' extension. If a different behavior is required, it will be necessary to overload the GetReport method of the ReportDesignerController.

Implement Custom Storage

The purpose of the report definition storage is to describe how to browse, open, save, and delete reports from the Web Report Designer. The storage is configured as a setting of the ReportDesignerController.

The default implementation of the storage is the FileDefinitionStorage. It provides functionality for working with TRDP/TRDX report files stored on the server-side file system. To load the reports from a custom storage, change the implementation of the definition storage like this:

public class CustomDefinitionStorage : IDefinitionStorage
{
    private string baseDir;

    public string BaseDir
    {
        get
        {
            return this.baseDir;
        }
    }

    public CustomDefinitionStorage(string baseDir)
    {
        this.baseDir = baseDir;
    }

    public IEnumerable<string> ListDefinitions()
    {
        // Retrieve all available reports in the database and return their unique identifiers.
        throw new NotImplementedException();
    }

    public byte[] GetDefinition(string definitionId)
    {
        // Retrieve the report definition bytes from the database.
        throw new NotImplementedException();
    }

    public void SaveDefinition(string definitionId, byte[] definition)
    {
        // Save the report definiton bytes to the database.
    }

    public void DeleteDefinition(string definitionId)
    {
        // Delete the report definition from the database.
    }
}

Then you can set the new definition storage implementation in the ReportDesignerController.

public ReportDesignerController()
{
    //...

    this.ReportDesignerServiceConfiguration = new ReportDesignerServiceConfiguration
    {
        DefinitionStorage = new CustomDefinitionStorage(this.reportsDefinitionsPath),
        SettingsStorage = new FileSettingsStorage(this.reportsSettingsPath)
    };
}

The BaseDir property sets the base path for the reports and the resources they reference. For example, CSV or JSON files used in CsvDataSource and JsonDataSource components.

In this article
Not finding the help you need? Improve this article