New to Telerik Reporting? Download free 30-day trial

Set the File Path of JSON or CSV DataSource Through Report Parameter

Environment

Product Progress® Telerik® Reporting

Description

This article explains how to set the file path of the CSV or JSON file of JsonDataSource or CsvDataSource through a Report Parameter.

Solution

You can use the Utility function Uri to set the CSV/JSON file through a report parameter. For example:

  1. Create a Report Parameter called uriParameter - Approaches for Adding Report Parameters
  2. Set the Binding property of the data item that will use the data source component:

Property path: DataSource.Source

Expression: = Uri(Parameters.uriParameter.Value, "relative")

Workaround for older versions

If the Uri function is not available in the report designer, the desired functionality can be also achieved through a custom User function that returns the Uri of the CSV or JSON file based on the passed report parameter. You can follow the steps below:

  1. Create a new Class Library and add the static method below. In this case, the sample is for an absolute path:

    public static Uri setCsvSource(string path)
    {
    return new Uri(path, UriKind.Absolute);
    }
    
  2. Build the project so that an assembly(.dll) is generated

  3. Register the generated .dll as it is explained in the Extending Report Designer article. You will need to open the Telerik.ReportDesigner.exe.config file and add the following XML:

    <Telerik.Reporting>
    <AssemblyReferences>
        <add name="MyUserFunction" />
    </AssemblyReferences>
    </Telerik.Reporting>
    
  4. Set the following Binding to the data item that uses the data source component:

    Property path: DataSource.Source

    Expression: = MyUserFunction.Class1.setCsvSource(Parameters.csvSource.Value)

    Parameters.csvSource.Value should hold the path to the CSV file.

  5. If you display the report in a .NET Framework application, you will need to register the DLL in the web.config/app.config file of the project too:

    <Telerik.Reporting>
    <AssemblyReferences>
        <add name="MyUserFunction" />
    </AssemblyReferences>
    </Telerik.Reporting>
    

Demo

You can find a sample report with the Uri function, a project with for the User Function, and a report that uses it in our GitHib repository.

In this article