Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CR .net Export Problem. Help!!

Status
Not open for further replies.

JoeRoc

Programmer
Dec 19, 2001
4
0
0
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top