 |
|
|
|
Streaming Crystal Output to a Browser
|
|
|
 |
|
Location: Blogs Andy's Blog |
|
| Posted by: host |
12/14/2004 7:19 PM |
This is a handy function that accepts an Export Format (i.e. PDF, Word or Excel) and streams a Crystal Report output back to the browser client.
Private Sub ExportReport(ByVal iFormatType As ExportFormatType) Dim sTargetPath As String, sTargetExt As String, sContentType As String Dim fs As FileStream Dim FileSize As Long Dim GenDS As DataSet Dim oRD As New ReportDocument() Dim crReportObject As ReportObject Dim oExO As ExportOptions Dim oExDo As New DiskFileDestinationOptions()
'Build Target Filename Select Case iFormatType Case ExportFormatType.Excel sTargetExt = ".xls" sContentType = "application/vnd.ms-excel" Case ExportFormatType.PortableDocFormat sTargetExt = ".pdf" sContentType = "application/pdf" Case ExportFormatType.WordForWindows sTargetExt = ".doc" sContentType = "application/msword"
End Select
sTargetPath = Server.MapPath("") & "\Export\" & Session.SessionID & sTargetExt
oRD = GetReportDocument() 'Export to PDF oExDo.DiskFileName = sTargetPath oExO = oRD.ExportOptions oExO.ExportDestinationType = ExportDestinationType.DiskFile oExO.ExportFormatType = iFormatType oExO.DestinationOptions = oExDo oRD.Export() oRD.Close()
'Send the file to the user that made the request Response.Clear() Response.Buffer = True Response.AddHeader("Content-Type", sContentType) Response.AddHeader("Content-Disposition", "file;filename=" & Left(ViewState("ReportName"), Len(ViewState("ReportName")) - 4) & sTargetExt) fs = New FileStream(sTargetPath, 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()
End Sub
|
|
| Permalink |
Trackback |
Comments (3)
Add Comment
|
Re: Streaming Crystal Output to a Browser
|
By Anonymous on
7/18/2007 10:57 AM
|
Hello Andy. In Windows form of Visaul Studio for .NET I have CrystalReportViewer control - report is Employee Requisitions. I would like to export this report into PDF format, attach it at email and send to user. Can I use ExportReport() method of CrystalReportViewer to do this? Any help with code. Thanks in advance. This is not for publishing on web. Nebojsa
Email: nebojsa_minic@rogers.com
|
|
|
Re: Streaming Crystal Output to a Browser
|
By Anonymous on
7/18/2007 10:58 AM
|
Hello Andy. In Windows form of Visaul Studio for .NET I have CrystalReportViewer control - report is Employee Requisitions. I would like to export this report into PDF format, attach it at email and send to user. Can I use ExportReport() method of CrystalReportViewer to do this? Any help with code. Thanks in advance. This is not for publishing on web. Nebojsa
Email: nebojsa_minic@rogers.com
|
|
|
Re: Streaming Crystal Output to a Browser
|
By Anonymous on
7/18/2007 2:30 PM
|
Sure you can use Export() like in the code above. Then you would want to use an SMTP mail message to get it to the user. You can look up System.Web.Mail but basically you need to
Imports System.Web.Mail
... and then create a MailMessage object with attachments. Just google System.Web.Mail, MailMessage, SMTP and you will find lots of stuff
|
|
|
|
 |
|
 |
|
|