I have downloaded the whitepapers for Exporting to PDF. I can understand most of the code that is there, but there is a declaration that is very confusing. Here is the code that they have:
‘ Define Crystal Reports variables
Dim crReportDocument As ReportDocument ' ***** Is this the report name?
Dim crExportOptions As ExportOptions ' ***** ?????? ExportOptions is NOT a DataType
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions ' ***** Same thing here
Dim Fname as String
‘ The following code can be placed directly after the call to
‘ InitializeComponent() in the form’s constructor, or inside of
‘ a Button_Click event where the button is used by the client to
‘ get a printable copy of the report.
CrReportDocument = New ReportDocument()
‘ The following line of code loads the sample report “Chart.rpt” that installs
‘ with Visual Studio .NET
CrReportDocument.Load (“C:\Program Files\Microsoft Visual Studio .NET\Crystal
Reports\Samples\Reports\Feature Examples\Chart.rpt”)
Fname = “c:\exports\” & Session.SessionID.ToString & “.pdf”
CrDiskFileDestinationOptions = New DiskFileDestinationOptions()
CrDiskFileDestinationOptions.DiskFileName = Fname
CrExportOptions = crReportDocument.ExportOptions
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
CrReportDocument.Export()
‘ The following code writes the pdf file to the Client’s browser.
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(Fname)
Response.Flush()
Response.Close()
‘delete the exported file from disk
System.IO.File.Delete(Fname)
What am I doing wrong? Is there something I need to add? Like
Imports.... Thank you. Ron.
I believe that your code looks correct. Below are some code comments that I hope help you:
Dim crReportDocument As ReportDocument ' This is the Crystal object when you load it, then you get your report name
Dim crExportOptions As ExportOptions ' ExportOptions is a collection that you populate later in the code
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions ' Another collection used with Export Options
....
CrReportDocument.Load (“C:\Program Files\Microsoft Visual Studio .NET\Crystal
Reports\Samples\Reports\Feature Examples\Chart.rpt”)
' This is where the report is "named"
What is the problem that you are encountering?
Eric Landes
MADNUG President http://www.madnug.net
Crystal Alliance Editor
Blog http://aspadvice.com/blogs/elandes
Microsoft MVP
VS.NET 2003 is telling me that the following are not valid datatypes ReportDocument ExportOptions DiskFileDestinationOptions Is there something above that I need to add? Ron
Make sure you have these imports in your file: Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.IO For more information on exporting Crystal Reports to PDF, you can take a look at Richard Dudley's article here: http://dotnetjunkies.com/WebLog/richard.dudley/archive/2004/05/26/14543.aspx
hth
Now I'm getting the following error: Exception Details: CrystalDecisions.CrystalReports.Engine.DataSourceException: Query Engine Error: 'C:\DOCUME~1\RONTAB~1\ASPNET\LOCALS~1\Temp\temp_37d01134-89b9-4d12-a45d-d80966898b39.rpt' Does this mean that the items in
my DataSet do not match with what the report is expecting? But wouldnt that crash before the export? I'll try sending the dataset to a CRviewer instead and see if that crashes with the same error. Thanks Ron.
Yeah the Column names in your DataSet need to match the field names inside your report. I'm struggling to get my Report to work too...now I see a blank report in PDF format, with no data. At least I know I can generate PDF now...
I realized exactly what I did wrong just moments afterI clicked POST. hehehehe. I created an XSD dataset called dsFollowup.xsd But I had copied and pasted the code from another page and forgot to change the name. OOPS!! Now I get the report, but it's blank.
I'm wondering if it is because I'm pulling info from 2 tables with an inner join in my SQL statement. The XSD file has both tables in it and they are linked. I tried to send the dataset to a CrystalReportViewer object and it was blank too. Any Ideas? Ron.
In the report, have you linked the two tables together? You should be able to do that when you pick the datasource. Also I couldn't link up the two tables when I create the typed DataSet - any ideas?
>I'm wondering if it is because I'm pulling info from 2 tables with an inner join in my SQL statement. The XSD file has both tables in it and they are linked. The XSD should be the schema for the RESULTS, not the SOURCE. If you use an inner join, you are only
returning a single table from your database. The XSD should look like the resultset that is returned. The columns must have the same name and be in the same order.
How would I do that? if my SELECT statement is: SELECT tblQuestions.QuestionNbr, tblQuestions.QuestionText, tblAnswers.Answer, tblAnswers.Comment FROM tblAnswers JOIN tblQuestions ON tblQuestions.QuestionNbr = tblAnswers.QuestionNbr AND tblQuestions.QuestionYear
= tblAnswers.SchoolYear WHERE tblQuestions.QuestionYear = '2005' AND tblAnswers.SchoolNbr = '0101' AND tblAnswers.Complete = 0 AND tblAnswers.Answer = 0 What should my Elements in the XSD page look like. I tried to create elements with the same name and in
the same order in the same grouping. Then I tried dragging the columns from the Server Explorer into the same element group. Neither way worked. Thanks Ron.
Capt_Ron
Member
586 Points
139 Posts
Trying to Convert to PDF - Help
Oct 19, 2004 02:56 PM|LINK
ericlandes
Contributor
5475 Points
1095 Posts
ASPInsiders
MVP
Re: Trying to Convert to PDF - Help
Oct 19, 2004 03:24 PM|LINK
MADNUG President http://www.madnug.net
Crystal Alliance Editor
Blog http://aspadvice.com/blogs/elandes
Microsoft MVP
Capt_Ron
Member
586 Points
139 Posts
Re: Trying to Convert to PDF - Help
Oct 19, 2004 04:40 PM|LINK
joelny
Participant
904 Points
191 Posts
Re: Trying to Convert to PDF - Help
Oct 19, 2004 04:54 PM|LINK
JL
Capt_Ron
Member
586 Points
139 Posts
Re: Trying to Convert to PDF - Help
Oct 20, 2004 05:35 PM|LINK
joelny
Participant
904 Points
191 Posts
Re: Trying to Convert to PDF - Help
Oct 20, 2004 05:59 PM|LINK
JL
Capt_Ron
Member
586 Points
139 Posts
Re: Trying to Convert to PDF - Help
Oct 20, 2004 06:40 PM|LINK
joelny
Participant
904 Points
191 Posts
Re: Trying to Convert to PDF - Help
Oct 20, 2004 07:22 PM|LINK
JL
rjdudley
Star
10145 Points
1976 Posts
ASPInsiders
Re: Trying to Convert to PDF - Help
Oct 20, 2004 09:08 PM|LINK
Capt_Ron
Member
586 Points
139 Posts
Re: Trying to Convert to PDF - Help
Oct 20, 2004 11:34 PM|LINK