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:
- Create a Report Parameter called uriParameter - Approaches for Adding Report Parameters
- 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:
-
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); }
Build the project so that an assembly(
.dll
) is generated-
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>
-
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.
-
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.