Error when exporting a (.rpt) to (.pdf) in .NET

0
Dim rutaDB As String = "C:\prueba\Crystal\bdfabrica.mdb"
Dim informe As String = "C:\prueba\LisVolOperCliDetalle.rpt"
Dim informePDF As String = "C:\prueba\LisVolOperCliDetalle.pdf"
Public Sub imprimirInforme()

            fechaInicio = CDate("10/10/2016")
            fechaFin = CDate("10/10/2017")
            diaInicio = (fechaInicio).Day
            diaFinal = (fechaFin).Day
            mesInicio = (fechaInicio).Month
            mesFinal = (fechaFin).Month
            annoInicio = (fechaInicio).Year
            annoFinal = (fechaFin).Year

            Try
            With informeRpt
                .Database.Tables(0).Location = rutaDB
                .RecordSelectionFormula = "{RegIVARe.Fecha_Factura} in Date(" & annoInicio & "," & mesInicio & "," & diaInicio & ") to Date(" & annoFinal & "," & mesFinal & "," & diaFinal & ") AND " & "{RegIVARe.Cod_Cliente} = " & codCliente & ""
            End With


            parFecInicio.Name = "fechaInicio"
            fInicio.Value = fechaInicio
            parFecInicio.CurrentValues.Add(fInicio)
            parametros.Add(parFecInicio)


            parFecFinal.Name = "fechaFinal"
            fFinal.Value = fechaInicio
            parFecFinal.CurrentValues.Add(fFinal)
            parametros.Add(parFecFinal)

            cr.ReportSource = informeRpt
            cr.DisplayGroupTree = False
            cr.Dock = DockStyle.Fill
            cr.ParameterFieldInfo = parametros

            Dim frmReporte As New Form
            With frmReporte
                .Controls.Add(cr)
                .WindowState = FormWindowState.Maximized
            End With

            frmReporte.Show()
            Thread.Sleep(2000)
        informeRpt.ExportToDisk(ExportFormatType.PortableDocFormat, informePDF)

        Catch ex As Exception
        MessageBox.Show("Error: " & ex.Message)
        End Try
    End Sub

The code generates the report well, but at the time of creating the pdf it gives me an error:

en esta linea 
informeRpt.ExportToDisk(ExportFormatType.PortableDocFormat, informePDF)

This is the error in tiempo de ejecución :

It's like you're looking for the .rpt in the temporary folder.

But at the time of export, if you are taking the route where my .pdf is

Does anyone know where the problem may be?

Thanks

    
asked by Sam.Gold 05.04.2017 в 17:59
source

2 answers

0

Hi maybe you could do it in an easier way. Sometimes when you have the report displayed you have the option to choose a printer in one of these printers you could choose the one related to the pdf program and export it to pdf, in my case I use Foxit Reader and it puts a pdf printer printer every pdf reader program generates a printer, you could use that medium and make the job easier.

    
answered by 05.04.2017 в 18:08
0

Well, if you want to use a button, you could do something like this:

Public Shared Function ExportToPDF(rpt As ReportDocument, NombreArchivo As String) As String
Dim vFileName As String = Nothing
Dim diskOpts As New DiskFileDestinationOptions()

Try
    rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
    rpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat

            'Este es la ruta donde se guardara tu archivo.
    vFileName = "c:\Reporte\" & NombreArchivo
    If File.Exists(vFileName) Then
        File.Delete(vFileName)
    End If
    diskOpts.DiskFileName = vFileName
    rpt.ExportOptions.DestinationOptions = diskOpts
    rpt.Export()
Catch ex As Exception
    Throw ex
End Try

Return vFileName

End Function

and then call the button

Private Sub btnReporte_Click(sender As Object, e As EventArgs)
Dim _reporte As ReportePersonal = Reporte.ObtenerReportePersonal()
Dim frm As New frmReportePersonal(_reporte)
frm.Show()

Utilidades.ExportToPDF(_reporte, "rptPersonal.pdf")

End Sub

Analyze it and adapt it. Greetings

    
answered by 05.04.2017 в 18:45