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

Apply Template at RunTime

3 Answers 252 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 09 May 2012, 02:45 PM
Hi there

I have reporting DLL setup up that I reference in my web application.

There is a report type called DefaultCertificate in this class lib, I can change the datasource dynamically, but what I want to do is apply a template at runtime as well.

Some clients will have their own template, but with the same fields. I know there is something like a trdx file that keeps the template? But can't seem to find decent documentation on it.

Long story short:

1. How do I save my current or any other report design to a trdx file
2. How would I apply that trdx file to the certificate at run time?
        DefaultCertificate applicantCertificate = new DefaultCertificate();
        applicantCertificate.DataSource = application.GetCertificateDetails(applicantID, applicationYear);
 
//something to do the following?
applicantCertificate.Template = "location of template trdx file";

Thanks.

3 Answers, 1 is accepted

Sort by
0
Jako
Top achievements
Rank 1
answered on 11 May 2012, 09:51 AM
ok, it seems I started the wrong way around.

What I did now was create a report in the Telerik report designer and saved it to a trdx file in each clients folder.

Then I use this code to apply the clients report and assign a dynamic datasource and export to a PDF
string certificateName = applicationYear + "Certificate.pdf";
 string certificatePath = document.CreateDocumentDirectories(user, Server.MapPath("../client/documents"));      
 
 
 using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(certificatePath + @"\certificate_template.trdx"))
 {
     System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Telerik.Reporting.Report));
 
     Telerik.Reporting.Report applicantCertificate = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
     applicantCertificate.DataSource = application.GetCertificateDetails(applicantID, applicationYear);       
 
     Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
     Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", applicantCertificate, null);
 
     using (FileStream fs = new FileStream(certificatePath, FileMode.Create))
     {
         fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
     
 }
0
Jako
Top achievements
Rank 1
answered on 18 Jun 2012, 01:52 PM
ok, since "upgrading" to the purchased lisence and the Q2 version I am having some problems.

I had some code like this:
string reportPath = Server.MapPath("./reports") + @"\reportClients.trdx";
using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(reportPath))
{
    System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Telerik.Reporting.Report));
 
    Telerik.Reporting.Report clientReport = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
    Report report = new Report();
 
    clientReport.DataSource = report.GetClientReportData(businessTypeID, siteID);
 
    uxClientReport.Report = clientReport;
    uxClientReport.RefreshReport();
}
But now its complaing: There was an error reflecting type 'Telerik.Reporting.Report'.
Also some warnings about:
'Telerik.Reporting.Report.implicit operator Telerik.Reporting.ReportSource(Telerik.Reporting.Report)' is obsolete: 'The implicit Report to ReportSource conversion is obsolete. Please create InstanceReportSource instead.'

Any ideas how to convert this code to match up with the new Q2 release?
0
IvanY
Telerik team
answered on 21 Jun 2012, 01:52 PM
Hello Jako,

In order to fix the error and deserialize correctly you have to use our ReportXmlSerializer. More information and the updated code snippets you can find in our Serializing Report Definition in XML help article.

About your initial question - the Report object does not expose Template property and we will need additional clarification on what do you mean by template. Additionally the .trdx is the report definition simply serialized in xml.

From your explanations it seems that you have data sources and reports with identical structure and different data/layout and you want to use DataSource1 with Report1, Report2, etc, respectively Report1 with DataSource1, DataSource2, etc. If that is the case you can check our Programmatic Control of Reports section. If not please elaborate

Regards,
IvanY
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
Jako
Top achievements
Rank 1
Answers by
Jako
Top achievements
Rank 1
IvanY
Telerik team
Share this question
or