Problem displaying as PDF

2 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 27 Feb 2014 Link to this post

    Hi

    I'm having trouble getting the code example http://www.telerik.com/help/reporting/faq-display-pdf-browser.html


    This line - Dim result As Telerik.Reporting.Processing.RenderingResult = reportProcessor.RenderReport("PDF", typeReportSource, Nothing)
    throws the following error:

    Value cannot be null.
    Parameter name: type

    Andy

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
     
        ExportToPDF("NoiseTestBlanks.trdx")
     
    End Sub
     
    Sub ExportToPDF(ByVal reportToExport As String)
     
        Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor()
        Dim typeReportSource As New Telerik.Reporting.TypeReportSource()
     
        ' reportToExport is the Assembly Qualified Name of the report
        typeReportSource.TypeName = reportToExport
     
        Dim result As Telerik.Reporting.Processing.RenderingResult = reportProcessor.RenderReport("PDF", typeReportSource, Nothing)
     
        Response.Clear()
        Response.ContentType = result.MimeType
        Response.Cache.SetCacheability(HttpCacheability.Private)
        Response.Expires = -1
        Response.Buffer = True
        'Uncomment to handle the file as attachment
        'Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", reportToExport))
        Response.BinaryWrite(result.DocumentBytes)
        Response.End()
     
    End Sub

  2. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 03 Mar 2014 Link to this post

    Hello Andy,

    The used example is based on report definition created with Visual Studio. If you want to use a trdx (report definition created with the standalone Telerik Report Designer) you have to utilize UriReportSource as shown in the following updated code snippet. Just make sure that the report definition is available in the application bin or update the URI accordingly.
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
      
        ExportToPDF("NoiseTestBlanks.trdx")
      
    End Sub
      
    Sub ExportToPDF(ByVal reportToExport As String)
      
        Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor()
        Dim reportSource As New Telerik.Reporting.UriReportSource()
     
        reportSource.Uri= reportToExport
      
        Dim result As Telerik.Reporting.Processing.RenderingResult = reportProcessor.RenderReport("PDF", reportSource, Nothing)
      
        Response.Clear()
        Response.ContentType = result.MimeType
        Response.Cache.SetCacheability(HttpCacheability.Private)
        Response.Expires = -1
        Response.Buffer = True
        'Uncomment to handle the file as attachment
        'Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", reportToExport))
        Response.BinaryWrite(result.DocumentBytes)
        Response.End()
      
    End Sub

    Regards,
    Peter
    Telerik

    New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

  3. DevCraft banner
Back to Top