I've upgraded my .net framework to Crystal Decisions 9.2.33 from 9.1.33, and now I get the following error trying to export any report:
Access to report file denied. Another program may be using it.
Here's the code:
Private Sub ExportReport()
Dim rptExport As ReportObject
Dim rptExportOpt As ExportOptions
Dim destOpt As New DiskFileDestinationOptions()
Dim rptName As String
Dim respType As String
rptName = Session("report"
rptLocPath = Server.MapPath("/"
& "pathtorptdirectory\" & rptName
rptDestPath = Server.MapPath("/"
& "pathtoexportdirectory\"
rpt.Load(rptLocPath) 'Loads selected report
SetParam(rptName) 'Sets date parameters in report
Logon() 'Sets database connection parameters for each table in report
rptDestFile = rptDestPath & Left(rptName, rptName.Length - 4) & Session.SessionID.ToString & txtFileType.Text
Session("ReportExport"
= rptDestFile
destOpt.DiskFileName = rptDestFile
rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
rpt.ExportOptions.DestinationOptions = destOpt
Select Case txtFileType.Text
Case ".pdf"
rpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
respType = "application/pdf"
Case ".doc"
rpt.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows
respType = "application/doc"
Case ".xls"
rpt.ExportOptions.ExportFormatType = ExportFormatType.Excel
respType = "application/xls"
Case ".rpt"
rpt.ExportOptions.ExportFormatType = ExportFormatType.CrystalReport
respType = "application/rpt"
End Select
If System.IO.File.Exists(rptDestFile) Then
System.IO.File.Delete(rptDestFile)
End If
rpt.Export()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = respType
Response.WriteFile(rptDestFile)
Response.Flush()
Response.Close()
System.IO.File.Delete(rptDestFile)
End Sub
Joe Handley
dehandley@hotmail.com
Access to report file denied. Another program may be using it.
Here's the code:
Private Sub ExportReport()
Dim rptExport As ReportObject
Dim rptExportOpt As ExportOptions
Dim destOpt As New DiskFileDestinationOptions()
Dim rptName As String
Dim respType As String
rptName = Session("report"
rptLocPath = Server.MapPath("/"
rptDestPath = Server.MapPath("/"
rpt.Load(rptLocPath) 'Loads selected report
SetParam(rptName) 'Sets date parameters in report
Logon() 'Sets database connection parameters for each table in report
rptDestFile = rptDestPath & Left(rptName, rptName.Length - 4) & Session.SessionID.ToString & txtFileType.Text
Session("ReportExport"
destOpt.DiskFileName = rptDestFile
rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
rpt.ExportOptions.DestinationOptions = destOpt
Select Case txtFileType.Text
Case ".pdf"
rpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
respType = "application/pdf"
Case ".doc"
rpt.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows
respType = "application/doc"
Case ".xls"
rpt.ExportOptions.ExportFormatType = ExportFormatType.Excel
respType = "application/xls"
Case ".rpt"
rpt.ExportOptions.ExportFormatType = ExportFormatType.CrystalReport
respType = "application/rpt"
End Select
If System.IO.File.Exists(rptDestFile) Then
System.IO.File.Delete(rptDestFile)
End If
rpt.Export()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = respType
Response.WriteFile(rptDestFile)
Response.Flush()
Response.Close()
System.IO.File.Delete(rptDestFile)
End Sub
Joe Handley
dehandley@hotmail.com