Schenz
Well-known member
I'm not sure if this is a Service issue, a printing issue, or a CR issue, but I am not able to print a report using the following code from a Windows Service:
The same code works just fine in a Windows Application.
Has anyone printed anything from a Windows Service? Or more specifically has anyone printed a Crystal Report from a Windows Service?
VB.NET:
Private Sub showPackingSlipReport(ByVal ds As DataSet)
' Declare variables and get the export options.
Dim crReportDocument As rptOverstockPackingSlip
Dim exportOpts As New ExportOptions
Dim diskOpts As New DiskFileDestinationOptions
Dim myLog As EventLog = GetLog()
Dim strTodayOrderPath As String = GetTodayOrderPath()
'Dim strExePath As String = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
Dim strFileName As String = strTodayOrderPath & Now.ToShortDateString.Replace("/", ".") & " " & Now.ToShortTimeString.Replace(":", ".") & "Packing Slip.pdf"
myLog.WriteEntry("V-Commerce Service Log", "Printing Packing Slip", EventLogEntryType.Information)
Try
crReportDocument = New rptOverstockPackingSlip
crReportDocument.SetDataSource(ds)
Catch ex As Exception
myLog.WriteEntry("V-Commerce Service Log", "Error: " & ex.ToString & ControlChars.CrLf & ControlChars.CrLf & "Stack Trace: " & ex.StackTrace.ToString, EventLogEntryType.Error)
End Try
Try
exportOpts = crReportDocument.ExportOptions
' Set the export format.
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
Catch ex As Exception
myLog.WriteEntry("V-Commerce Service Log", "Error: " & ex.ToString & ControlChars.CrLf & ControlChars.CrLf & "Stack Trace: " & ex.StackTrace.ToString, EventLogEntryType.Error)
End Try
' Set the disk file options.
Try
diskOpts.DiskFileName = strFileName
exportOpts.DestinationOptions = diskOpts
' Export the report.
Try
crReportDocument.Export()
Catch ex As Exception
myLog.WriteEntry("V-Commerce Service Log", "Error: " & ex.ToString & ControlChars.CrLf & ControlChars.CrLf & "Stack Trace: " & ex.StackTrace.ToString, EventLogEntryType.Error)
End Try
[color=Red] crReportDocument.PrintToPrinter(1, True, 0, 0) ' This is where it bombs out[/color]
Catch ex As IndexOutOfRangeException
myLog.WriteEntry("V-Commerce Service Log", "Error: " & ex.ToString & ControlChars.CrLf & ControlChars.CrLf & "Stack Trace: " & ex.StackTrace.ToString, EventLogEntryType.Error)
Catch ex As Exception
myLog.WriteEntry("V-Commerce Service Log", "Error: " & ex.ToString & ControlChars.CrLf & ControlChars.CrLf & "Stack Trace: " & ex.StackTrace.ToString, EventLogEntryType.Error)
End Try
crReportDocument.Dispose()
myLog.Dispose()
crReportDocument = Nothing
myLog = Nothing
exportOpts = Nothing
diskOpts = Nothing
strTodayOrderPath = Nothing
End Sub
The same code works just fine in a Windows Application.
Has anyone printed anything from a Windows Service? Or more specifically has anyone printed a Crystal Report from a Windows Service?