SpriteHand
Module Border
  Streaming Crystal Output to a Browser
Module Border
Location: BlogsAndy'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



Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Blog_List
Module Border
Module Border Module Border
Module Border
  Subscribe
Module Border

RSS

Module Border Module Border
Module Border
  Diversions
Module Border

DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game was submitted as an entry to the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

INFO AND CODE



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2008 andy.beaulieu.com - Login