Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Export to PDF problem Post Reply Post New Topic
Author Message
moosetracker
Newbie
Newbie


Joined: 31 Jul 2008
Location: United States
Online Status: Offline
Posts: 14
Quote moosetracker Replybullet Topic: Export to PDF problem
    Posted: 31 Jul 2008 at 8:33am
Sorry if this is handled in the book. I have ordered one, it just has yet to arrive.
 
In Asp.net for VB.. I am trying to get the export to pdf to work. I am following a tutorial of how to get it to work from a C# example that did work.
 
In VB I get no compilation error. But, when running I get the following error.
 
"Object Reference not set to an instance of the object."
 
I do rebind during a postback, and watching in debug it does hit the code. This fixed other navigation errors, so I know it to be working.
 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

BindReport()

Else

CrystalRpt = CType(Session("CrystalRpt"), CrystalDecisions.CrystalReports.Engine.ReportDocument)

End If

CrystalReportViewer1.ReportSource = CrystalRpt

End Sub

But in the following code I get the error, which seems to me, It doesn't think I have rebound the data..
 

' Stop buffering the response

Response.Buffer = False

' Clear the response content and headers

Response.ClearContent()

Response.ClearHeaders()

Try

' Export the Report to response stream in PDF format and file name Customers

CrystalRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "Customers_rptName")

' There are other format options available such as word, Excel, CVS, and html in the ExportFormatType

' Enum given by crystal reports

Catch exp As Exception

MsgBox(exp.Message)

End Try

 

TIA to anyone who can help..

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 31 Jul 2008 at 12:28pm

Unfortunately, the book doesn't cover streaming the PDF file via HTTP (looks like I need to put that on my to-do list for the .NET 2008 book...). But which line is triggering the error.

For you to get an object referene error, then I would put a trace on the code and make sure that CrystalRpt is being assigned the report prior to the export happening. I would bet that its a timing issue of when events are triggered. Plus, you should move the code in Page_Load() to Page_Init() this will prevent problems with timing as well.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
moosetracker
Newbie
Newbie


Joined: 31 Jul 2008
Location: United States
Online Status: Offline
Posts: 14
Quote moosetracker Replybullet Posted: 31 Jul 2008 at 12:39pm
Sorry..
 
This is the line of code that is having the problem.
 
 

CrystalRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "Customers_rptName")

Also as a side note, your book was already a help. It pointed out why I could display the report, but it either displayed blank  when hitting the pageing or errored when hitting the Navigation bar. I had the Session when not postback.. But I did not have it set the way you did for postback. When I altered it per the small sample of a chapter It worked great. This is what got me to walk in and ask my boss for the book.
 
Just incase you need it. This is the code for creating the session.
 
 

If Session("CrystalRpt") Is Nothing Then

Dim conninfo As New ConnectionInfo

With conninfo

.ServerName = "Ultiserv\ultisql"

.DatabaseName = "Northwind"

.UserID = "prog"

.Password = "underdog"

End With

CrystalRpt.Load(Server.MapPath("Samplerpt01.rpt"))

Me.CrystalReportViewer1.ReportSource = CrystalRpt

Dim RepTbls As Tables = CrystalRpt.Database.Tables

For Each RepTbl As Table In RepTbls

Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo

RepTblLogonInfo.ConnectionInfo = conninfo

RepTbl.ApplyLogOnInfo(RepTblLogonInfo)

Next

Session("CrystalRpt") = CrystalRpt

End If

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 31 Jul 2008 at 5:07pm

If that is the line triggering the error, put a break point on the IsPostBack line and the line with the error. I'm guessing that the line with the error is firing first. Secondly move teh Page_Load() code to Page_Init() - I talk about this in the VS2008 book-. That will help to force it to load first as well.

Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
moosetracker
Newbie
Newbie


Joined: 31 Jul 2008
Location: United States
Online Status: Offline
Posts: 14
Quote moosetracker Replybullet Posted: 01 Aug 2008 at 6:39am
Thanks..
 
I got further.. but got a new problem (not so bad)..
 
Other problem was not in any code I was showing you.. Sorry.. I had added code to Close & dispose of the crystal report on page_unload.. It was a late addition, and must have been after my last check of navigation working and first check of PDF working... This was firing on every refresh of the page, therefore The simple call for the held session wasn't working because.. the session was no longer in memory.. Duhhhhhh.... Newbies, gotta love us.
 
New error.. I now get the pdf page.. The whole thing. But still end with an error message.   A thread Abort exception. "Thread was being aborted"
 
 
So in this.. The try seems to work, but the exception still fires..
 

Try

' Export the Report to response stream in PDF format and file name Customers

CrystalRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "Customers_rptName")

' There are other format options available such as word, Excel, CVS, and html in the ExportFormatType

' Enum given by crystal reports

Catch exp As Exception

MsgBox(exp.Message)

End Try

 

Seems like I could just capture this error and surpress it.. But is there some way I should be ending it cleaner?

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 01 Aug 2008 at 12:14pm
Glad you got this cleaned up. Unfortunately, I don't know why you're getting that error.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.032 seconds.