Saving report to disk

3 posts, 1 answers
  1. Larry
    Larry avatar
    11 posts
    Member since:
    Aug 2012

    Posted 07 Sep 2019 Link to this post

    I'm trying to follow the info on this page: 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. Answer
    Neli avatar
    285 posts

    Posted 10 Sep 2019 Link to this post

    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, 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.

    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
  3. Larry
    Larry avatar
    11 posts
    Member since:
    Aug 2012

    Posted 10 Sep 2019 in reply to Neli Link to this post

    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);
Back to Top