Hello, We have working HTML5 Report viewer with back-end WCF servics.
Now , we are looking for additional step ahead where we can generate the report programmatically and send it over as email attachment.
I have followed the article "Exporting Report Programmatically" & able to create the report programmatically, however when I am assigning the data to report source it goes as NULL.
ReportViewer1.ReportSource = reportSource;
The serveic returns valid data in Telerik.Reporting.ObjectDataSource but it goes as NULL while assigning it to Report viewer.
Any thoughts, what could be wrong here ?
topSpendersDataList = BusinessManager.GetTopSpenders();
Telerik.Reporting.ObjectDataSource objectDataSource =
new
Telerik.Reporting.ObjectDataSource();
objectDataSource.DataSource = topSpendersDataList;
// GetData returns a DataSet with three tables
objectDataSource.DataMember =
"GetTopSpenders"
;
// Indicating the exact table to bind to. If the DataMember is not specified the first data table will be used.
objectDataSource.CalculatedFields.Add(
new
Telerik.Reporting.CalculatedField(
"FirstName"
,
typeof
(
string
),
"=Fields.firstName"
));
// Adding a sample calculated field.
objectDataSource.CalculatedFields.Add(
new
Telerik.Reporting.CalculatedField(
"LastName"
,
typeof
(
string
),
"=Fields.lastName"
));
// Creating a new report
Telerik.Reporting.Report report =
new
Telerik.Reporting.Report();
// Assigning the ObjectDataSource component to the DataSource property of the report.
report.DataSource = objectDataSource;
// Use the InstanceReportSource to pass the report to the viewer for displaying
Telerik.Reporting.InstanceReportSource reportSource =
new
Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
// Assigning the report to the report viewer.
ReportViewer1.ReportSource = reportSource;
Thanks,
Nitin
7 Answers, 1 is accepted
In the provided example you are creating an empty report and then bind it to data. Without creating a report template and using the fields from the data source in the report, the result will be an empty page.
If your intent is to use Telerik Reporting, details how to start creating Telerik Reports and display them in viewers are available in the Quickstart help section. For the purpose, my recommendation is to start with the provided Report Designers. The overview articles contain descriptions of the designers UI.
To start test to create a new ClassLibrary project with the minimum system requirements of Telerik Reporting, and add a new item. To connect your data, you can use any of the reporting data source components, where you can use report parameters to control the data retrieval e.g. SqlDataSource Wizard step 4 which is based on Using Parameters with the SqlDataSource component.
An example of supplying data via service is available in the Connecting Telerik Reporting to OData feeds blog post.
Example how to export and send a report via e-mail is available in the Send Telerik Report as email attachment code library post.
Regards,
Stef
Telerik
Thank you Stef for your reply.
We already have one application with HTML5 report viewer integrated, and it works well. Now we are working on another small backend utility through which we expect to generate the report programmatically and send it over email (w/o having report viewer since its backend utility app)
As you have noticed in the code block above, the challenge we are facing is to get the report data configured programmatically, Unfortunately there is no resource explains the steps on how to do it step by step.
Would appreciate if you can point us to any resource available or suggest any modification in the code snippet in order to have the report populate with data source.
Thanks,
Nitin
Telerik reports are templates which must contain fields from the assigned to them data. The data can be changed at run-time by modifying the corresponding DataSource properties.
To create a report at run-time, please check the recommendations in my post here.
If you have a report template already (CS|VB file or TRDX file), you can just iterate the report instance's Items and change the needed DataSource properties. Consider the example in the Changing the connection string dynamically according to runtime data KB article.
Once you have the ready report instance, it can be exported in PDF and attached to an e-mail - Send Telerik Report as email attachment.
Regards,
Stef
Telerik
Appreciate your response. We were trying to follow the suggestion to use the existing report template (.CS file) as below -
var connectionString =
"Data Source=(local);Initial Catalog=TempDB;Integrated Security=SSPI"
;
var connectionStringHandler =
new
ReportConnectionStringManager(connectionString);
var sourceReportSource =
new
UriReportSource { Uri =
"R_TopSpenders_Report.cs"
};
var reportSource = connectionStringHandler.UpdateReportSource(sourceReportSource);
this
.reportViewer1.ReportSource = reportSource;
this
.reportViewer1.RefreshReport();
However while DeserializeReport we are getting exception as
data at the root level
is
invalid. line 1 position 1.
We noticed that the xmlReader is coming as None at using (var xmlReader = System.Xml.XmlReader.Create(textReader, settings))
Is this something known with .CS Report Template or are we missing anything here?
Thanks,
Nitin
Such error can be seen if the application uses an earlier version of Telerik Reporting than the version used to produce the TRDX file.
Please check which Telerik Reporting version is used the application, and test opening a TRDX file created with the same version.
Regards,
Stef
Telerik
Hello Stef,
We are using Telerik Reporting Version= 8.2.14.1204 (Q3 2014 SP1). Also as you can see we are going with .CS report template file instead of TRDX file.
The same .CS file is being used in our HTML5 Report viewer and it works fine there. So we thought of using the same template file (.CS) here while generating report programatically,
CAa you advise on how to use the .CS file template here in such cases?
Thanks,
Nitin
When you are working with reports created in Visual Studio (VB|CS files) they can be wrapped in TypeReportSource (use the report's type assembly qualified name) or InstanceReportSource (use an instance of the report). The UriReportSource allows you to wrap TRDX files.
For more details, please check report sources.
Regards,
Stef
Telerik