Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Write a PDF

Status
Not open for further replies.

warpped

MIS
Jan 19, 2000
59
US
I have a VS2003 .Net 1.1 app. that when the page loads, it calls a sub routine that exports a Crystal report to a PDF. It then redirects to another page that displays the PDF in the browser.

I am upgrading my apps. to VS2005 and .Net 2.0. The above no longer works, all I get is a blank page. The PDF is getting generated, it's just not displaying.

I placed a button on the main page and instead of calling the sub routine from the page_load event, I call it from the button_click. It works from the button_click but not the page_load event.

When I step through the code, it is going through everything properly.

Why would it work from a button_click and not the page_load event?

Thanks
 
Here is the code...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack = True Then
Dim fname As String

fname = Trim(CType(Session("FNAME"), String))

Response.ClearContent()
Response.ClearHeaders()
Response.Buffer = True
Response.Expires = -1

Response.ContentType = "application/pdf"
Response.WriteFile(fname)
Response.Flush()
Response.Close()

' Delete the exported report file
'File.Delete(fname)
End If
End Sub
 
Is the page_load firing at all or is it firing but not displaying the pdf? Do a

Response.Write("test")
Exit Sub

at the top of it just to see if it is even firing first.
 
I did that. It is firing, just not displaying PDF.
 
Sorry to point out the obvious again but

Response.Write(fname)

to make sure what you think is in fname is actually there.
 
Yeah. I did. I even hard coded the path to the file. If I launch the page from a command button it works.
 
Jeez. What about a response.redirect instead? Man this worries me, I'm supposed to go from 1.1 to 2 too, but I'm hearing lots of weird stuff like this, not good.
 
This is just one of many issues I'm working through. Luckily, they have all been minor.

I start with a link that opens a page (invreport.aspx) that runs the Crystal Report. Crystal then exports as PDF. Then I do a response.redirect to the (reportviewer.aspx) page which does the response.write.

The only thing that is clicked is the initial link which opens invreport.aspx where the report is run from the page_load. The redirect is executed pointing to reportviewer.aspx where page_load is executed displaying the PDF.

If I put a button on invreport.aspx and execute the report routine, everything works fine. It doesn't like page_load for some reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top