C#/.NET - Working with Telerik.Reporting, how to get a Telerik.Reporting.Report from .trdp

61 Views Asked by At

I am trying to do two things, I am trying to get a Telerik.Reporting.Report object from an absolute path for a given .trdp file and then turning that Report instance into a PDF byte[]. I have been fighting ChatGPT all day and it has given me useless after useless solution.

I have the following code which takes an absolute path and gets me a byte[] but I really need a Report instance before the byte array so I can adjust some properties of the report design prior to rendering it

public static byte[] GetReportBytes(string reportPath)
{
    var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    var reportSource = new UriReportSource();
    reportSource.Uri = reportPath;

    var result = reportProcessor.RenderReport("PDF", reportSource, new Hashtable());

    if (result.HasErrors)
        throw new Exception(result.Errors[0].Message);

    return result.DocumentBytes;
}

I would like to split this logic out into to methods:

  1. public Report GetReport(string reportPath)
  2. public byte[] GetReportBytes(Report report)

The reason for this is because I will have .trdp files in my application and I will ultimately render them as PDFs to send in an email as an attachment. But I need to be able to adjust the report design at runtime prior to render. Is this possible? I'm ok with having to update the .trdp with the new design or creating a serialized xml first. I just can't seem to get AI to work at all.

0

There are 0 best solutions below