This is a migrated thread and some comments may be shown as answers.

How can I get report DataSources programmatically

6 Answers 2326 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
Tursunkhuja asked on 23 Oct 2019, 06:59 AM

In my report I'm using 2 data sources: webServiceDataSource and jsonDataSource. The main DataSource for the report is webServiceDataSource. I'm using jsonDataSource just for storing some report meta data and I want to read this jsonDataSource source from c# code.

Part of my code:

Telerik.Reporting.Report report = ... - (it's report object)

var dataSource = report.DataSource;

We have access to DataSource property. But, we don't have access to DataSources collection property in code. I tried to use DataSources property in Watch window(Visual Studio 2019), it is now showing on intellisense, but if you write DataSources property manually then it works.

Question is how can I read DataSources collection property and get jsonDataSource programmatically?

6 Answers, 1 is accepted

Sort by
0
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 23 Oct 2019, 07:02 AM
We have access to DataSource property. But, we don't have access to DataSources collection property in code. I tried to use DataSources property in Watch window(Visual Studio 2019), it is not showing on intellisense, but if you write DataSources property manually then it works.
Question is how can I read DataSources collection property and get jsonDataSource programmatically?

I tried to use DataSources property in Watch window(Visual Studio 2019), it is now showing on intellisense, but if you write DataSources property manually then it works.

0
Todor
Telerik team
answered on 25 Oct 2019, 02:27 PM

Hi Tursunhuja,

Each DataSource component that is created in the Report definition is stored by itself, not in a collection. The corresponding property is private when created in the VS designer. The Report object doesn't have a DataSources property - check Report class.

By design, the data sources are accessible only through the data items they are attached to. All the items in the report definition created with the VS designer are private and can be accessed from the Report.Items collection with their names. The data sources can be accessed from the corresponding data item DataSource property. If you need to access all the data sources, you need to iterate through all data items and get their DataSource properties.

Regards,
Todor
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 26 Oct 2019, 06:04 AM

Hi Todor,

I want to have JsonDataSource in my report to store information about report metadata like: ReportName, Description, Properties list(it's customized parameters. Here I want to put DataType for a parameter to set datatype that's not clr datatype, so it's related to our framework), and some other report metadata. This JsonDataSource is not attached to any data items. It's just using programmatically. That's why I can not get access through data items. What do you suggest on this?

Other scenario is I need to create that JsonDataSource in code and add this in the DataSources collection of a report file. What do you suggest on this?

0
Accepted
Todor
Telerik team
answered on 30 Oct 2019, 01:56 PM

Hello Tursunhuja,

The CLR Reports are normal classes that extend the base Telerik.Reporting.Report class. If you need to store some custom data in the report, you may introduce a dedicated property in it, e.g. Dictionary, etc. and set its value, for example, in the constructor of the Report. You may also define a JsonDataSource property as public so that you can use it outside the corresponding report, e.g. 'myReport.MySource'. When you create data sources with the Visual Studio designer, they will be private properties. For that reason, you will need to modify the code of the report definition manually, e.g. in the constructor outside the InitializeComponent method:

public partial class Dashboard : Telerik.Reporting.Report
{
    public Dictionary<string, string> MyProperty { get; set; }
    public JsonDataSource MySource { get; set; }
	
    public Dashboard()
    {
        /// <summary>
        /// Required for Telerik Reporting designer support
        /// </summary>
        InitializeComponent();

        this.MyProperty = new Dictionary<string, string>();// include some data
        this.MySource = new JsonDataSource();// include some data
    }
}

Regards,
Todor
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 04 Nov 2019, 03:58 PM

Hi Todor,

My report is not extending the base Telerik.Reporting.Report class and it's not created by Visual Studio designer. It's created by Telerik Report Designer tool. I create json data source to store some custom data(or report metadata) like ReportName, Description, DataType property for a parameter and so on. I never attache this JsonDataSource to any data items. I just want to open the telerik report file(.trdp, .trdx) programmatically and somehow read JsonDataSource or if it does not exist then I should create and add JsonDataSource inside the report file. How to do that?

0
Todor
Telerik team
answered on 07 Nov 2019, 10:16 AM

Hi Tursunhuja,

The DataSources can be accessed only from data items. The collection with all data sources kept in the Report is not publicly exposed. When you need to access a data source, you may insert a dummy List (e.g. hidden), and attach the data source to the List - this way you will be able to access the data source through the List.

Note that it is not straight-forward to take the data from an embedded JsonDataSource as it is encoded - check for example a TRDX report with JsonDataSource. The data sources are meant to feed the report items with data and not for custom use. The Reporting engine fetches the data while processing the report.

As a workaround applicable for both declarative and CLR reports I can suggest introducing a hidden report parameter that holds the JSON data as a string. You may access this value programmatically and use it as necessary in the code.

Regards,
Todor
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
Todor
Telerik team
Share this question
or