Solved

exporting report to pdf file

Posted on 2004-08-13
7
747 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:tentavarious
  • 4
  • 2
7 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 11793468
0
 
LVL 42

Expert Comment

by:frodoman
ID: 11795184
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
0
 

Author Comment

by:tentavarious
ID: 11795398
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()
 
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 100

Expert Comment

by:mlmcc
ID: 11795565
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
0
 

Author Comment

by:tentavarious
ID: 11796001
I get the same error either way.  If i take the space out or put a slash in, same error occurs
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
ID: 11796294
I assume you have write permissions to the directory being used.

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11798223
Glad I could help

mlmcc
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now