Bonjour,
Dans un bouton ASP.net en code-behind, j'exporte un rapport Crystal Report en format pdf comme ceci :
Sub Export_PDF()
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim Fname As String
Dim fs As FileStream
Dim FileSize As Long
crReportDocument.Load("path_et_fichier.rpt")
crReportDocument.Refresh()
Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tbCurrent In crReportDocument.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = monserveur
.UserID = monuser
.Password = monpassword
.DatabaseName = mabd
End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent
Fname = "path_et_fichier" & ".pdf"
crDiskFileDestinationOptions.DiskFileName = Fname
crExportOptions = crReportDocument.ExportOptions
crExportOptions.DestinationOptions = crDiskFileDestinationOptions
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
crReportDocument.Export()
Response.ClearContent()
Response.ClearHeaders()
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment;filename=RapportBooking_" & Left(Session.SessionID, 3) & ".pdf;")
fs = New FileStream(Fname, FileMode.Open)
FileSize = fs.Length
Dim bBuffer(CInt(FileSize)) As Byte
fs.Read(bBuffer, 0, CInt(FileSize))
fs.Close()
Response.BinaryWrite(bBuffer)
Response.Flush()
Response.Close()
Response.ClearContent()
Response.End()
File.Delete(Fname)
crReportDocument.Close()
End Sub
Le code fonctionne très bien. Sauf que je ne suis pas capable de reprendre le contrôle dans le code après l'export, pour, par exemple, afficher un msgbox. Il demeure comme en suspens, comme si la fonction Export_PDf n'était pas terminée. Qu'est-ce qui me manque?
Merci à l'avance!
Maroxye 