VB.Net method to print all available reports with a single button click

I have created a windows form with a crystal reports viewer, a combo box to select a report to view, and a button that I would like to (Print All Reports). The print button in the viewers toolbar will print the report currently being viewed. I want the button in my application to print all the reports without viewing them.

I have following code, but it throws an exception of type 'CrystalDecisions.Shared.CrystalReportsException' occurred in CrystalDecisions.CrystalReports.Engine.dll Additional information: Load report failed.

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Windows.Forms


Public Class frmReport

Private Sub frmReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub cboReport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboReport.SelectedIndexChanged

    Dim rptCustomer As New Customer
    Dim rptEmployee As New Employee

    Select Case cboReport.SelectedIndex
        Case 0
            Me.CrystalReportViewer1.ReportSource = rptCustomer
        Case 1
            Me.CrystalReportViewer1.ReportSource = rptEmployee

    End Select

End Sub

Private Sub btnPrintReports_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintReports.Click

    Dim rptCustomer As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim rptEmployee As New CrystalDecisions.CrystalReports.Engine.ReportDocument

    rptCustomer.Load("Customer.rpt")
    rptEmployee.Load("Employee.rpt")

    rptCustomer.PrintToPrinter(1, False, 0, 0)
    rptEmployee.PrintToPrinter(1, False, 0, 0)

End Sub


End Class

I have searched and failed to find a solution. Any suggestions?

Answers


When you call CrystalDecisions.CrystalReports.Engine.ReportDocument's Load method you need to specify a path and a filename.

Also, have you granted NETWORK SERVICE permissions on Windows\Temp?


Need Your Help

How to “reset” C# SqlCommand object so I can re-use it in a loop

c# foreach ssis sqlcommand

I have this code in a foreach loop that calls a sql function for each folder

Better Capture to Session Affiliate Id from GET in PHP

php session cookies affiliate affiliates

Can someone help me clean this up and make it more logical? I'm fried right now and can't seem to get a good line of code written :)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.