Although we're using VS2002, the following code allows a given report (after setting parameters information, etc.) to be exported to either PDF, Excel or Word format and saved as a file on the web server's file system. The "objRpt" variable is instantiated as a ReportDocument object. Hope this helps a bit!
===================================================
Try
Dim ExportPath As String
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim FName As String
Dim tFileExtn As String
Dim tExportDir As String
Dim tFileName As String
Dim tDirName As String
Dim blnShowRpt As Boolean = False
crDiskFileDestinationOptions = New DiskFileDestinationOptions()
crExportOptions = objRpt.ExportOptions
' Based on the format the user selects...
Select Case Request.QueryString("format").Trim.ToUpper
Case "PDF"
blnShowRpt = True
tFileExtn = ".pdf"
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
Case "WORD"
tFileExtn = ".doc"
crExportOptions.ExportFormatType = ExportFormatType.WordForWindows
Case "EXCEL"
tFileExtn = ".xls"
crExportOptions.ExportFormatType = ExportFormatType.Excel
Case "CSV"
tFileExtn = ".csv"
End Select
' Specify an export directory (tExportDir already previously specified)
If Directory.Exists(tExportDir) = False Then Directory.CreateDirectory(tExportDir)
FName = "test" & tFileExtn
tFileName = FName
FName = tExportDir & "\" & FName
crDiskFileDestinationOptions.DiskFileName = FName
' Set the required report ExportOptions properties
With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.DestinationOptions = crDiskFileDestinationOptions
End With
Try
objRpt.Export()
If blnShowRpt Then
'This code directly exports and opens the PDF file
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile("../" & tDirName & "/" & tFileName)
Response.Flush()
Response.Close()
' Delete the PDF from the file system since it has been streamed to the browser
System.IO.File.Delete(FName)
Else
' Provide a link allowing the user access to the exported Word/Excel file on the file system
hlnkViewFile.NavigateUrl = "../" & tDirName & "/" & tFileName
Catch err As Exception
' Do error handling here
End Try
Catch ex as Exception
' Do error handling here
End Try
-- Creator of the XModuleSB Application:
--