Print Crystal Reports (web)

Posted on 2005-05-04
Last Modified: 2012-06-22
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 web.
Question by:sborchers
    LVL 33

    Accepted Solution

    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

                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/"
                        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.AppendHeader("Content-disposition", ContentDisposition)
                Response.Expires = -1
                Response.Buffer = True
                Response.ContentType = contentType

            Catch ex As Exception
            End Try


    Author Comment

    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?
    LVL 33

    Expert Comment

    logon errors, uggh!  They could be just about anything.  Are you using push or pull model for your report?

    Author Comment

    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.

    Author Comment

    Is there any more help i can get on printing crystal reports from a web page or with the logon error described above?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now