All source code in .Net Ask a .Net Pro Discussion Forum Categories All jobs in .Net
Exports,crystal,report,using,streams
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 666,891. lines
 Jobs: 818. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for .Net.
SQL Backup/Restore using SMO
By Visual Soft Computers on 2/6


Click here to see a screenshot of this code!flexi grid
By maytel.mynt on 1/12

(Screen Shot)

Using Excel in VB2010 (VB10)
By Alberto Torres on 2/5


Click here to see a screenshot of this code!SermonNotes
By arifliminto86 on 2/5

(Screen Shot)

Click here to see a screenshot of this code!A.net Programm to add new database
By Rohit Kanugo on 2/5

(Screen Shot)

Access_Database _Add
By Rohit Kanugo on 2/4


Add new DataBase Through Coding for a IT Company
By Rohit Kanugo on 2/4


Click here to see a screenshot of this code!Numbert To Word Conversion Short and Simple Code
By Opal Raj Ghimire on 2/3

(Screen Shot)

Click here to see a screenshot of this code!Monopoly Game
By arifliminto86 on 2/1

(Screen Shot)

Click here to see a screenshot of this code!Write Text to File, Write Binary To File
By brandon teoh on 2/1

(Screen Shot)

Click here to see a screenshot of this code!Movable Resizable Runtime Controls VB2005 Version
By SC Project on 2/1

(Screen Shot)

Desktop Email Client
By Avinash Kumar Sharma on 1/30


Website Source Code Grabber
By Avinash Kumar Sharma on 1/30


Click here to see a screenshot of this code!Auto Scrolling Label Method (autoscrolling textbox)
By Kenny28 on 1/30

(Screen Shot)

EL-Bandido Time Monitoring System Daily Record
By Ian Formanes on 1/30


Click here to see a screenshot of this code!Weather
By Jsvnascar on 1/29

(Screen Shot)

Mini NetMeeting
By Ian Formanes on 1/28


EL-Bandido
By Ian Formanes on 1/27


Click here to see a screenshot of this code!RegionMaker
By silviu petre on 1/27

(Screen Shot)

calculations class
By silviu petre on 1/26


Click here to see a screenshot of this code!Introduction to ADO.NET(OLEDBCO NNECTION)
By jay celeste on 1/21

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Crystal Report export to PDF without writing to disk on server

Print
Email
 
VB icon
Submitted on: 8/27/2003 10:16:57 AM
By: Mark Pearson 
Level: Intermediate
User Rating: By 6 Users
Compatibility:VB.NET, ASP.NET

Users have accessed this code 76390 times.
 
 
     Exports a crystal report to a pdf using two streams.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    //**************************************
    //     
    // for :Crystal Report export to PDF wit
    //     hout writing to disk on server
    //**************************************
    //     
    I downloaded some of this almost a year ago and don't remember where or from whom.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: Crystal Report export to PDF wi
    //     thout writing to disk on server
    // Description:Exports a crystal report 
    //     to a pdf using two streams.
    // By: Mark Pearson
    //
    // Inputs:Object array of parameters, re
    //     lative path to report, optional set para
    //     meters boolean (defaults to true)
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=1503&lngWId=10    //for details.    //**************************************
    //     
    
    use like this:
    replace $ with a as psc would not upload due to the word $ss in cl$ss and other words
    Dim cp As New CryPrinter
    Dim params(0) As String
    params(0) = "hello"
    cp.CreateReport("a_report.rpt", params)
    cp=nothing
    Here's the cl$ss:
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.Web.Design
    Imports System.IO
    Public Cl$ss CryPrinter
    Inherits System.Web.UI.Page
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
    #Region " Web Form Designer Generated Code "
    'This call is required by the Web Form Designer. 
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    End Sub
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer 
    'Do not modify it using the code editor. 
    InitializeComponent()
    End Sub
    #End Region
    Public Sub CreateReport(ByVal sReport As String, ByVal arParams As Array, _
    Optional ByVal DoParams As Boolean = True)
    Dim oRpt As New ReportDocument
    Dim oSubRpt As New ReportDocument
    Dim Counter As Integer
    Dim crSections As Sections
    Dim crSection As Section
    Dim crReportObjects As ReportObjects
    Dim crReportObject As ReportObject
    Dim crSubreportObject As SubreportObject
    Dim crDatabase As Database
    Dim crTables As Tables
    Dim crTable As Table
    Dim crLogOnInfo As TableLogOnInfo
    Dim crConnInfo As New ConnectionInfo
    Dim crParameterValues As ParameterValues
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterRangeValue As ParameterRangeValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldDefinition As ParameterFieldDefinition
    Dim crParameterFieldDefinition2 As ParameterFieldDefinition
    Dim strFile As String
    Dim fi As FileInfo
    Dim tstr As String
    Dim sPath As String
    Dim sReportPath As String = HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH") & sReport
    Dim pos As Integer
    Try
    tstr = Microsoft.VisualBasic.Format(Now, "MM/dd/yyyy HH:mm:ss")
    'load report 
    oRpt.Load(sReportPath)
    'log on to SQL server 
    'Report code starts here
    'Set the database and the tables objects to the main report 'oRpt'
    crDatabase = oRpt.Database
    crTables = crDatabase.Tables
    'Loop through each table and set the connection info 
    'Pess the connection info to the logoninfo object then apply the 
    'logoninfo to the main report
    For Each crTable In crTables
    With crConnInfo
    .ServerName = SERVER_NAME
    .UserID = Session("sUser")
    .Pessword = Session("sPessword")
    End With
    crLogOnInfo = crTable.LogOnInfo
    crLogOnInfo.ConnectionInfo = crConnInfo
    crTable.ApplyLogOnInfo(crLogOnInfo)
    Next
    'Set the sections collection with report sections
    crSections = oRpt.ReportDefinition.Sections
    'Loop through each section and find all the report objects
    'Loop through all the report objects to find all subreport objects, then set the 
    'logoninfo to the subreport
    For Each crSection In crSections
    crReportObjects = crSection.ReportObjects
    For Each crReportObject In crReportObjects
    If crReportObject.Kind = ReportObjectKind.SubreportObject Then
    'If you find a subreport, typecast the reportobject to a subreport object
    crSubreportObject = CType(crReportObject, SubreportObject)
    'Open the subreport
    oSubRpt = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
    crDatabase = oSubRpt.Database
    crTables = crDatabase.Tables
    'Loop through each table and set the connection info 
    'Pess the connection info to the logoninfo object then apply the 
    'logoninfo to the subreport
    For Each crTable In crTables
    With crConnInfo
    .ServerName = SERVER_NAME
    .UserID = Session("sUser")
    .Pessword = Session("sPessword")
    End With
    crLogOnInfo = crTable.LogOnInfo
    crLogOnInfo.ConnectionInfo = crConnInfo
    crTable.ApplyLogOnInfo(crLogOnInfo)
    Next
    End If
    Next
    Next
    ' Set the parameters
    If DoParams Then
    ''Get the collection of parameters from the report
    crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields()
    For Counter = 0 To UBound(arParams)
    crParameterFieldDefinition = crParameterFieldDefinitions.Item(Counter)
    ''Get the current values from the parameter field.
    crParameterValues = crParameterFieldDefinition.CurrentValues
    If Not IsArray(arParams(Counter)) Then
    ''Set the current values for the parameter field 0
    crParameterDiscreteValue = New ParameterDiscreteValue
    crParameterDiscreteValue.Value = arParams(Counter)
    ''Add the first current value for the parameter field
    crParameterValues.Add(crParameterDiscreteValue)
    Else
    crParameterRangeValue = New ParameterRangeValue
    crParameterRangeValue.StartValue = arParams(Counter)(0)
    crParameterRangeValue.EndValue = arParams(Counter)(1)
    crParameterValues.Add(crParameterRangeValue)
    End If
    ''All current parameter values must be applied for the parameter field.
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    Next
    End If
    Dim s As System.IO.MemoryStream = oRpt.ExportToStream(ExportFormatType.PortableDocFormat)
    ' the code below will create pdfs in memory and stream them to the browser
    ' instead of creating files on disk.
    With HttpContext.Current.Response
    .ClearContent()
    .ClearHeaders()
    .ContentType = "application/pdf"
    .AddHeader("Content-Disposition", "inline; filename=Report.pdf")
    .BinaryWrite(s.ToArray)
    .End()
    End With
    Catch ex As System.Exception
    LogError("cryPrinter.CreateReport", ex.ToString)
    Finally
    Erase arParams
    End Try
    End Sub
    End Cl$ss

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/27/2003 3:22:14 PMMark Pearson

Please replace the LogError call with your own error logging function or delete it. I tried to upload the code as a zip but the file could not be found.
(If this comment was disrespectful, please report it.)

 
9/24/2003 10:30:28 PM

Could you explain a little bit more on how to implement the code? Do we need to add a Crystalreportviewer in the aspx page? I paste the code in my aspx.vb page and make the necessary changes, such as report name and parameters. When i load the page, I get a blank page in my IE. There's no error message, so, I don't know where had gone wrong.
(If this comment was disrespectful, please report it.)

 
10/2/2003 2:51:15 PMMark Pearson

You don't need a crystal report viewer. A database name being set incorrectly will cause a blank page in IE. Otherwise, try putting a breakpoint after the catch line and viewing the exception message or tostring property.
(If this comment was disrespectful, please report it.)

 
11/11/2003 7:17:09 AM

al
(If this comment was disrespectful, please report it.)

 
11/13/2003 1:00:32 PM

I'm getting an error with de function
(If this comment was disrespectful, please report it.)

 
11/13/2003 1:03:44 PM

I'm getting an error with the funcion ExportToStream
(If this comment was disrespectful, please report it.)

 
11/24/2003 12:01:50 AM

Error: ExportOptions can't be indexed because it has no default property.
(If this comment was disrespectful, please report it.)

 
1/12/2004 2:32:22 PMFatih ÜNAL

I could'nt find any method 'ExportToStream' for ReportDocument object..

net fw 1.0 installed I am using vs.net

does extra installation needed for ExportToReport method of ReportDocument
(If this comment was disrespectful, please report it.)

 
1/21/2004 3:04:06 AM

I tested the code on the server and it works but on a client adobe acrobat is opening and then a messagebox appears "the file don't begin by %pdf"
(If this comment was disrespectful, please report it.)

 
2/23/2004 1:53:12 PM

if i implement this on a client's web application - what kind of licensing is required from Crystal?
(If this comment was disrespectful, please report it.)

 
2/27/2004 6:53:25 AMFileTravel 747

hi i have used your code to attempt to produce the .PDF output.
(If this comment was disrespectful, please report it.)

 
3/22/2004 11:04:42 AM

I really need this to work in c#. Any help is appreciated.
(If this comment was disrespectful, please report it.)

 
5/20/2004 10:18:53 AM

Hi. I copied the code and inserted it in my aspx.vb page and made the necessary changes. However, when I load the page, I get this kind of error ...
Method not found: System.IO.Stream CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportF ormatType).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: Method not found: System.IO.Stream CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportF ormatType). Can any one help me on this? Your help is greatly appreciated. Thank you in advance.
(If this comment was disrespectful, please report it.)

 
6/3/2004 1:33:24 PM

I have tried your code, but I don't seem to have the ExportToStream method in my ReportDocument class. Could it be that it was missing in the early versions of Crystal Reports for VS.NET?
(If this comment was disrespectful, please report it.)

 
6/3/2004 1:34:56 PM

I tried your code, but I don't seem to have the ExportToStream method in my ReportDocument class. Could it be that it was missing from the earlier version of Crystal Reports for VS.NET?
(If this comment was disrespectful, please report it.)

 
8/12/2004 9:59:02 PM

Could you send me projects of this code to mtienaasc@yahoo.com
(If this comment was disrespectful, please report it.)

 
8/17/2004 9:10:27 AM

I tried your code, but I don't seem to
have the ExportToStream method in my
ReportDocument class.

Any help ???
(If this comment was disrespectful, please report it.)

 
6/14/2005 4:09:25 AM

me too, face same problem
"I tried your code, but I don't seem to
have the ExportToStream method in my
ReportDocument class"
(If this comment was disrespectful, please report it.)

 
2/23/2006 11:41:37 AMAngel

The class works perfectly !! Thanks a bunch. For people who aren't gettin this to work: create a new Class in your project (don't paste this code into an aspx page) and make sure you add the firs Imports lines into your class and you should be good to go!! Thanks again!
(If this comment was disrespectful, please report it.)

 
11/11/2006 7:50:43 AMcbgb

I got this code to work if the report has no parameters. But if the report has a parameter which must be passed to the stored procedure I keep getting the error message "stored proc name expects parameter ". But the parameter was supplied.
Any ideas anyone?


(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | .Net Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.