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

Saving report to disk

2 Answers 367 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Larry
Top achievements
Rank 1
Larry asked on 07 Sep 2019, 10:05 PM

I'm trying to follow the info on this page: https://docs.telerik.com/reporting/programmatic-exporting-report. However it doesn't show what the TypeName should be. I've tried many variations from other examples but I always get this error when the RenderReport line tries to execute: 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: type

 

var PDFSource = new TypeReportSource();
PDFSource.TypeName = "rptVAC";
var ReportProcessor = new ReportProcessor();
PDFSource.Parameters.Add(new Telerik.Reporting.Parameter("VACId", vacId));
var result = ReportProcessor.RenderReport("PDF", PDFSource, null);

2 Answers, 1 is accepted

Sort by
0
Accepted
Neli
Telerik team
answered on 10 Sep 2019, 10:12 AM

Hi Larry,

 

I noticed that you have asked the same question in a support ticket. I have answered there and will summarize my response also in this public thread for the benefit of our community :

The error message probably occurs because you use a string that is not a valid Assembly Qualified name for the report name. You need to use Assembly Qualified name for PDFSource.TypeName. The attached project demonstrates the following approach:

1. Create a report through the Visual Studio Report Designer.

2. Add a report parameter (VACId) from type Integer.

3. Display the report parameter's value in a textbox.

4. Add a new Console Application to the solution.

5. Add a reference to the Report Library.

6. Use the following piece of code to export the report and set a value for the parameter.

var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();

// set any deviceInfo settings if necessary
var deviceInfo = new System.Collections.Hashtable();

// ***CLR (CSharp) report definitions***
var reportSource = new Telerik.Reporting.TypeReportSource();

// reportName is the Assembly Qualified Name of the report
reportSource.TypeName = typeof(ReportLibrary2.rptVAC).AssemblyQualifiedName; 

// Pass parameter value with the Report Source if necessary
reportSource.Parameters.Add("VACId", 5);

Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);
string fileName = result.DocumentName + "." + result.Extension;
string path = "../../Reports";
string filePath = System.IO.Path.Combine(path, fileName);

using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}

 

Another reason for the error can be if you currently use version 13.1.19.618, but the report was created with an older version. This error is often seen when the report and assemblies are from different versions. The easiest way to ensure that all Reports and Assemblies are consistent in version and build would be to run the Upgrade Wizard. After running the Upgrade Wizard, restart Visual Studio and then you have to be able to run the report.

Regards,
Neli
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
Larry
Top achievements
Rank 1
answered on 10 Sep 2019, 06:37 PM

That did the trick!

If anyone else is reading this, it may be easier to write the file with the code below.

File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Test.pdf"), result.DocumentBytes);
Tags
General Discussions
Asked by
Larry
Top achievements
Rank 1
Answers by
Neli
Telerik team
Larry
Top achievements
Rank 1
Share this question
or