locked
Export a crystal report to pdf file got "Missing parameter values" error RRS feed

  • Question

  • User546194788 posted

    Dim crd As New ReportDocument
            crd.Load(Server.MapPath("crEligibility.rpt"))
            crd.SetDatabaseLogon("sa", "x6920", "svrmis2", "utility")
            crv1.ReportSource = crd
            Dim exp As New ExportOptions()
            exp.ExportFormatType = ExportFormatType.PortableDocFormat
            exp.FormatOptions = New PdfRtfWordFormatOptions()
            Dim req As New ExportRequestContext()
            req.ExportInfo = exp
            Dim st As System.IO.Stream
            st = crd.FormatEngine.ExportToStream(req)
            Response.ClearHeaders()
            Response.ClearContent()
            Response.ContentType = "application/pdf"
            Dim b(st.Length - 1) As Byte
            st.Read(b, 0, CInt(Fix(st.Length)))
            Response.BinaryWrite(b)
            Response.End()

    My Crystal report use store procedure as data source. Code1 is works. Once I add code2 to export to pdf, an error occured.

    How to fix it?      

     //code1 works fine and displays report on screen.


           Dim crd As New ReportDocument

            crd.Load(Server.MapPath("myCrystalReport.rpt"))

            crd.SetDatabaseLogon("myID", "Password", "ServerName", "DBName")

            CrystalReportViewer1.ReportSource = crd


    //code2  do not work said that "Missing parameter values" at line bold font.


            Dim exp As New ExportOptions()

            exp.ExportFormatType = ExportFormatType.PortableDocFormat

            exp.FormatOptions = New PdfRtfWordFormatOptions()

            Dim req As New ExportRequestContext()

            req.ExportInfo = exp

            Dim st As System.IO.Stream

            st =  CrystalReportViewer1.FormatEngine.ExportToStream(req) //Missing parameter values

            Response.ClearHeaders()

            Response.ClearContent()

            Response.ContentType = "application/pdf"

            Dim b(st.Length - 1) As Byte

            st.Read(b, 0, CInt(Fix(st.Length)))

            Response.BinaryWrite(b)

            Response.End()

    Thursday, July 15, 2010 9:55 AM

Answers

  • User1224194097 posted

    Try this

    this should print pdf to the page

     Dim crd As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            crd.Load(Server.MapPath("myCrystalReport.rpt"))
            crd.SetDatabaseLogon("myID", "Password", "ServerName", "DBName")
            Dim mem As IO.MemoryStream = DirectCast(crd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat),  _
                                         IO.MemoryStream)
            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "application/pdf"
            Response.BinaryWrite(mem.ToArray())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 15, 2010 5:25 PM

All replies

  • User1224194097 posted

    try this way

    'Get your report here instead of this
    'Change this
    Dim cr As New CrystalReport1()
    cr.SetDatabaseLogon("username", "password")
    Dim mem As MemoryStream = DirectCast(cr.ExportToStream(ExportFormatType.PortableDocFormat), MemoryStream)
    Response.Clear()
    Response.Buffer = True
    Response.ContentType = "application/pdf"
    Response.BinaryWrite(mem.ToArray())

    Thursday, July 15, 2010 2:43 PM
  • User546194788 posted

    I tried the way you show me but got an error said "CrystalReport1()" (myreport.rpt) not defined"

    Dim cr As New CrystalReport1()  //"CrystalReport1() not defined"

    Thursday, July 15, 2010 5:18 PM
  • User1224194097 posted

    Try this

    this should print pdf to the page

     Dim crd As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            crd.Load(Server.MapPath("myCrystalReport.rpt"))
            crd.SetDatabaseLogon("myID", "Password", "ServerName", "DBName")
            Dim mem As IO.MemoryStream = DirectCast(crd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat),  _
                                         IO.MemoryStream)
            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "application/pdf"
            Response.BinaryWrite(mem.ToArray())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 15, 2010 5:25 PM
  • User546194788 posted

    It works great. Thank you so much.

    But I still do not know why can not declare my report in code.

    Friday, July 16, 2010 4:02 PM
  • User1224194097 posted

    If you have the report in thw same web project you can create report document like this

    Dim report as new CrystalReport1()

    If you have the report in some other project that you are referencing, you will have to use the complete namespace name like

    Dim report as new ReportsProject.CrystalReport1()

    you can get the complete report class name from the report class

    Thanks

    Friday, July 16, 2010 4:25 PM
  • User546194788 posted

    MyReport is at the same project but can only declare it as ReportDocument like

    Dim crd As New CrystalDecisions.CrystalReports.Engine.ReportDocument 

    not like

    Dim report As New MyReport()

    Friday, July 16, 2010 4:33 PM
  • User1224194097 posted

    Honestly for this example, It worked, but usually I do like this

    Dim crd as New ReportDocument() and then crd.Load("path")

    or

    Public Function GetReport() As CrystalDecisions.CrystalReports.Engine.ReportClass

            Try
                Dim sType As String = "Reports.ReportName"
                Dim reportType As Type = Type.[GetType](sType, True, True)
                If reportType IsNot Nothing Then
                    ' Create an instance of the report and set it's datasource.
                    Dim rpt As CrystalDecisions.CrystalReports.Engine.ReportClass = _
                       DirectCast(Activator.CreateInstance(reportType), CrystalDecisions.CrystalReports.Engine.ReportClass)
                    Dim logOnInfo As New TableLogOnInfo()
                    logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("CrystalServer").ToString()
                    logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings("CrystalUser").ToString()
                    logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings("CrystalPassword").ToString()
                    Dim login As TableLogOnInfo
                    For Each tbl As CrystalDecisions.CrystalReports.Engine.Table In rpt.Database.Tables
                        login = tbl.LogOnInfo
                        login.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("CrystalServer").ToString()
                        login.ConnectionInfo.UserID = ConfigurationManager.AppSettings("CrystalUser").ToString()
                        login.ConnectionInfo.Password = ConfigurationManager.AppSettings("CrystalPassword").ToString()
                        tbl.ApplyLogOnInfo(login)
                    Next
                    Return rpt
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Function

    This returns me the Report. I have 100 reports, so I had this dynamic report creation which works well for me.

    I had a reports table with ID and ReportClassName and that takes care of the ReportClassName.

    Thanks.



    Friday, July 16, 2010 4:38 PM
  • User546194788 posted

    Thanks, 

    Friday, July 16, 2010 4:49 PM