Link to home
Start Free TrialLog in
Avatar of tentavarious
tentavarious

asked on

exporting report to pdf file

Hello all,
I am using visual studio.net 2003 and the bundled version of crystal reports.  I have created a web form that holds a report.  I would like for the user to click a button and export the report to a pdf.  There are errors in my code, visual studio does not like this line of code: Dim myReport as New web_printing_report, any ideas?

  Private Sub btnpdf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpdf.Click
        Dim myexportoptions As CrystalDecisions.Shared.ExportOptions
        Dim mydiskfile As CrystalDecisions.Shared.DiskFileDestinationOptions
        Dim myexportfile As String
        Dim myReport As New web_printing_report ' this line of code is not excepted
        myexportfile = c:\timecardreport\pdf " & _
        session.sessionid.tostring & ".pdf"
        mydiskfile = New CrystalDecisions.shared.DiskFileDestinationOptions
        mydiskfile.DiskFileName = myexportfile
        myexportoptions = myReport.exportoptions
        With myexportoptions
            .DestinationOptions = mydiskfile
            .ExportDestinationType = .ExportDestinationType.DiskFile
            .ExportFormatType = .ExportFormatType.PortableDocFormat
        End With
        myReport.export()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.WriteFile(myexportfile)
        Response.Flush()
        Response.Close()
        System.IO.File.Delete(myexportfile)

    End Sub
Avatar of Mike McCracken
Mike McCracken

For this line of code to work:

     Dim myReport as New web_printing_report

You need to add your report to your project ( I assume web_printing_report is the name of your report?).  In your solution explorer, rt-click on your project and select Insert Existing Item then browse to your report.  This will create a class for your report and you may then use "New reportname" to instantiate the report.

HTH

frodoman
Avatar of tentavarious

ASKER

Ok now i am getting this error

Server Error in '/tool/Tool128' Application.
--------------------------------------------------------------------------------

Invalid file name.
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: CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Invalid file name.

Source Error:


Line 60:             .ExportFormatType = .ExportFormatType.PortableDocFormat
Line 61:         End With
Line 62:         myReport.Export()    'my code stops here
Line 63:         Response.ClearContent()
Line 64:         Response.ClearHeaders()
 
There is a space in the file name  between \pdf and the sessionid

myexportfile = c:\timecardreport\pdf " & _
        session.sessionid.tostring & ".pdf"

Did you mean to have a \ there or have the files named pdfSESSIONID.pdf

mlmcc
I get the same error either way.  If i take the space out or put a slash in, same error occurs
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad I could help

mlmcc