Tengo un problema, necesito exportar un informe a PDF, aunque en el sitio de Crystal Decisions encontré el siguiente código, necesito que el usuario sea el que decida que nombre ponerle al archivo y dónde guardarlo en su computador, tiene alguien alguna sugerencia?
Código:
Sub ExportReport()
' This subroutine uses a case statement to determine the selected export format from the dropdownlist
' menu and then sets the appropriate export options for the selected export format. The report is
' exported to a subdirectory called "Exported".
' ********************************
'Check to see if the application directory has a subdirectory called "Exported".
'If not, create the directory since exported files will be placed here.
'This uses the Directory class of the System.IO namespace.
Dim ExportPath As String
ExportPath = Request.PhysicalApplicationPath + "Exported\"
If Directory.Exists(ExportPath) = False Then
Directory.CreateDirectory(Request.PhysicalApplicat ionPath + "Exported\")
End If
' ********************************
' First we must create a new instance of the diskfiledestinationoptions class and
' set variable called crExportOptions to the exportoptions class of the reportdocument.
crDiskFileDestinationOptions = New DiskFileDestinationOptions()
crExportOptions = crReportDocument.ExportOptions
'Find the export type specified in the dropdownlist and export the report. The possible export format
'types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT),
'HTML 3.2 (HTML) and HTML 4.0 (HTML)
'
'Though not used in this sample application, there are options that can be specified for various format types.
'When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
'first page, last page or page range to be exported.
'When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
'the column width etc.
Select Case DropDownList1.SelectedItem.Text 'this contains the value of the selected export format.
Case "Rich Text (RTF)"
'--------------------------------------------------------------------
'Export to RTF.
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions.DestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.RichText
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "Portable Document (PDF)"
'Export to PDF
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf"
'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "MS Word (DOC)"
'Export to Word
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "MS Excel (XLS)"
'Export to Excel
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "Crystal Report (RPT)"
'Export to Crystal reports:
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt"
'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.CrystalReport
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "HTML 3.2 (HTML)"
'Export to HTML32:
Dim HTML32Formatopts As New HTMLFormatOptions()
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML32
End With
With HTML32Formatopts
.HTMLBaseFolderName = ExportPath + "Html32Folder" 'Foldername to place HTML files
.HTMLFileName = "HTML32.html"
.HTMLEnableSeparatedPages = False
.HTMLHasPageNavigator = False
End With
crExportOptions.FormatOptions = HTML32Formatopts
'--------------------------------------------------------------------
'--------------------------------------------------------------------
Case "HTML 4.0 (HTML)"
'Export to Html 4.0:
Dim HTML40Formatopts As New HTMLFormatOptions()
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML40
End With
With HTML40Formatopts
.HTMLBaseFolderName = ExportPath + "Html40Folder" ' Foldername to place HTML files
.HTMLFileName = "HTML40.html"
.HTMLEnableSeparatedPages = True
.HTMLHasPageNavigator = True
.FirstPageNumber = 1
.LastPageNumber = 3
End With
crExportOptions.FormatOptions = HTML40Formatopts
End Select 'export format
'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
Try
' Export the report
crReportDocument.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Clicking on the "Export Report" button will run the ExportReport subroutine and export the report based on the
'selected format from the dropdownlist.
ExportReport()
End Sub