Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CrystalReportViewer for ASP.NET prints the toolbar

Posted on 2004-04-01
3
Medium Priority
?
2,449 Views
Last Modified: 2007-12-19
I have read "How to Design a good Crystal Report" from ehanoi and I think the conclusion is that Crystal Report Viewer for .Net does not come with a print button and if the toolbar is shown then when you print the report the toolbar appears on the report. If you hide the toolbar then of course it won't show on the printed page but you cannot navigate the report. This is bad, but what is worse is that when you print a report such as letters for individuals, it will print only the one displayed on the browser. Please let me know if this is so and there is no work around it. I pretty much have exhausted all options
0
Comment
Question by:Yves Mellet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
kssaran earned 1000 total points
ID: 10738457
Yes, You are right. But you can think of alternative in this way. When the user wants to print the report why dont u export the same report to a PDF File in the run time and parse it the new browser. Then user can take the print out from the PDF File, which will have only the output of the report.

Try the following code

    Dim strInvoiceNo As String
    Dim strSelectFormula As String
    Dim ServerName As String, UserId As String, Password As String

    Private Sub cmdShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowReport.Click
        ExportReport("servername", "username", "password")
    End Sub

    Private Sub ExportReport(ByVal ServerName As String, ByVal UserId As String, ByVal Password As String)
    'To Export the Result into a PDF File and display the Same in the window
        Dim myReport As New SampleReport()
        strInvoiceNo = txtInvoiceNo.Text
        strSelectFormula = "{invoice_header.inh_invoiceno} = '" + strInvoiceNo + "'"
        myReport.RecordSelectionFormula = strSelectFormula
        'Set the logon credentials of the main report
        LogonToDatabase(myReport.Database.Tables, ServerName, UserId, Password)

        'Modify the sub-report properties

        Dim mySection As CrystalDecisions.CrystalReports.Engine.Section
        Dim myReportObject As CrystalDecisions.CrystalReports.Engine.ReportObject
        Dim mySubReport As CrystalDecisions.CrystalReports.Engine.SubreportObject
        Dim mySubReportDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument

        'Loop through each section of the main report

        For Each mySection In myReport.ReportDefinition.Sections
            'Drill down into the section to see if there are any sub-reports
            For Each myReportObject In mySection.ReportObjects
                If myReportObject.Kind = _
                    CrystalDecisions.[Shared].ReportObjectKind.SubreportObject Then
                    mySubReport = CType(myReportObject, _
                        CrystalDecisions.CrystalReports.Engine.SubreportObject)

                    'Get a reference to the sub-report object
                    'so we can change its properties
                    mySubReportDoc = mySubReport.OpenSubreport(mySubReport.SubreportName)
                    'Set the logon credentials
                    LogonToDatabase(mySubReportDoc.Database.Tables, ServerName, UserId, Password)
                End If
            Next
        Next
        Dim myExportExt As String, myExportType As String, myExportFile As String
        Dim strExportType As String
        strExportType = "PDF"

        If strExportType = UCase("Excel") Then
            myExportExt = ".xls"
            myExportType = "application/vnd.ms-excel"
        ElseIf strExportType = UCase("HTML") Then
            myExportExt = ".html"
            myExportType = "application/html"
        ElseIf strExportType = UCase("PDF") Then
            myExportExt = ".pdf"
            myExportType = "application/pdf"
        ElseIf strExportType = UCase("RichText") Then
            myExportExt = ".rtf"
            myExportType = "application/rtf"
        ElseIf strExportType = UCase("Word") Then
            myExportExt = ".doc"
            myExportType = "application/msword"
        End If

        Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
        Dim myDiskFileDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions

        'myExportFile = Server.MapPath(".") & "\" & Session.SessionID.ToString & myExportExt
        myExportFile = "c:\winnt\temp\" & Session.SessionID.ToString & myExportExt

        myDiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
        myDiskFileDestinationOptions.DiskFileName = myExportFile
        myExportOptions = myReport.ExportOptions

        With myExportOptions

            .DestinationOptions = myDiskFileDestinationOptions
            .ExportDestinationType = .ExportDestinationType.DiskFile

            If strExportType = UCase("Excel") Then
                .ExportFormatType = .ExportFormatType.Excel
            ElseIf strExportType = UCase("HTML") Then
                .ExportFormatType = .ExportFormatType.HTML40
            ElseIf strExportType = UCase("PDF") Then
                .ExportFormatType = .ExportFormatType.PortableDocFormat
            ElseIf strExportType = UCase("RichText") Then
                .ExportFormatType = .ExportFormatType.RichText
            ElseIf strExportType = UCase("Word") Then
                .ExportFormatType = .ExportFormatType.WordForWindows
            End If
        End With

        'Exports the report to PDF format
        myReport.Export()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = myExportType
        Response.WriteFile(myExportFile)
        Response.Flush()
        Response.Close()

        System.IO.File.Delete(myExportFile)
    End Sub

    Private Sub LogonToDatabase(ByVal ReportTables As CrystalDecisions.CrystalReports.Engine.Tables, ByVal ServerName As String, ByVal UserId As String, ByVal Password As String)
    ' To Supply Logon Information to each and every Tables used in the Report
        Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim myConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
        Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo()
        myConnectionInfo.UserID = UserId
        myConnectionInfo.Password = Password
        myConnectionInfo.ServerName = ServerName
        myLogonInfo.ConnectionInfo = myConnectionInfo
        For Each myTable In ReportTables
            myTable.ApplyLogOnInfo(myLogonInfo)
        Next
    End Sub

End Class


0
 
LVL 13

Expert Comment

by:EwaldL
ID: 10743899
you get a print button on the web viewer if you upgrade to cr 9 or 10 developer or advanced.
0
 

Author Comment

by:Yves Mellet
ID: 10828368
Thanks for the help kssaran and Ewaldl. Particularly you kssaran for sending me all that code. It worked!
I would also like to follow Ewaldl advice to upgrade to cr9. I have the Advance edition but it  doesn't say it is for .net.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 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