[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

Print Crystal Reports (web)

I'm trying to print a Crystal Report from a Web page.  Is there a way to do that?  I have the data populated into the report but if you use the print button in the Internet Explorer it doesn't have the correct format.  The data in the report is the way i want it.  I'm using the Crystal Report that came with Visual Studio .net 2003.  The CrystalReportViewer doesn't have a print button on it and there are no properties that can be added to show a print button.  I'm building the application in vb.net web.
0
sborchers
Asked:
sborchers
  • 3
  • 2
1 Solution
 
raterusCommented:
I would suggest exporting the document to PDF and then printing that.  It's much cleaner.

Make a button that does something like this

        Dim oRpt As ReportDocument

        Try
            oRpt = New ReportDocument
            oRpt.Load(Server.MapPath("./SomeReport.rpt"), OpenReportMethod.OpenReportByDefault)

            Dim oStream As MemoryStream, ContentDisposition As String
            Dim exportType As ExportFormatType, contentType As String

            Dim filename As String = "export"
            Select Case UserSelectedExportType
                Case "PDF"
                    exportType = ExportFormatType.PortableDocFormat
                    contentType = "application/pdf"
                    ContentDisposition = "inline; filename=" & filename & ".pdf"

                Case "DOC"
                    exportType = ExportFormatType.WordForWindows
                    contentType = "application/msword"
                    ContentDisposition = "inline; filename=" & filename & ".doc"

                Case "XLS"
                    exportType = ExportFormatType.Excel
                    contentType = "application/vnd.ms-excel"
                    ContentDisposition = "attachment; filename=" & filename & ".xls"

                Case "HTML"
                    exportType = ExportFormatType.HTML40
                    contentType = "text/html"
                    ContentDisposition = "attachment; filename=" & filename & ".html"

                Case "RTF"
                    exportType = ExportFormatType.RichText
                    contentType = "application/rtf"
                    ContentDisposition = "attachment; filename=" & filename & ".rtf"

                Case Else
                    exportType = ExportFormatType.NoFormat
                    contentType = "application/octet-stream"
            End Select

            oStream = CType(oRpt.ExportToStream(exportType), MemoryStream)

            Response.Clear()
            Response.AppendHeader("Content-disposition", ContentDisposition)
            Response.Expires = -1
            Response.Buffer = True
            Response.ContentType = contentType
            Response.BinaryWrite(oStream.ToArray())

        Catch ex As Exception
            Throw
        Finally
            oRpt.Close()
            oRpt.Dispose()
        End Try

        Response.End()
0
 
sborchersAuthor Commented:
Thanks for the code.  I implemented it, but when i hit the line:   oStream = CType(oRpt.ExportToStream(exportType), MemoryStream):   I get a logon error.  Can you help me with that too?
0
 
raterusCommented:
logon errors, uggh!  They could be just about anything.  Are you using push or pull model for your report?
0
 
sborchersAuthor Commented:
I'm not exactly sure what push or pull model's mean??  I guess there is data in a sql table, i have a simple SQL Server connection and just bring back data from one table.  Then i moved a couple of the fields over to be on the crystal report.  And that was about all i've done... I would like to be able to pass a parameter so when i would use a stored procedure i could pass some sort of criteria.  But first i would like to be able to print the data.

Thanks again for your help.
0
 
sborchersAuthor Commented:
Is there any more help i can get on printing crystal reports from a web page or with the logon error described above?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now