Thursday, March 29, 2012

Opening PDF in ASP.NET

I'm trying to open an adobe acrobat PDF file from code VB\ASP.NET. The code below executes, but adobe never launches. Any suggestions...

Imports System
Imports System.Diagnostics
Imports System.ComponentModel

Web Form Cesigner Generated Code

Public Class PRINT_QUOTE
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) handles MyBase.Load

Process.Start("C:\Inetpub\wwwroot\BRAVO\my.pdf")

End Sub

End classWhy do you just redirect the user to the pdf file? This will cause the browser embeded acrobat to launch and handle the request.

Much easier than doing what you're doing.
When trying the response.redirect I get c:\inetpub\wwwroot\bravo\my.pdf in the IExplorer address field and have to click on Go to bring up my.pdf. Anyway to avoid having to clink on go, just force the PDF to launch right away?

Thanks
Paul
Found some cleaver code by searching around a little bit: This resolved my prob:

Response.ClearContent()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "Filename=my.pdf" )
Response.WriteFile( MapPath("my.pdf") )
Response.End()

Hope this helps someone else...
I am stuck with openning a PDF file in ASP.NET.
I tried doing this which doesn't work:

Response.Redirect(c:\mytest.pdf)

Why do you use WriteFile? And what is the purpose of MapPath function?

Hope you'll reply to this.
When redirecting you need to use an http url, not the physical location of the file on your computer. Example:


Response.Redirect("localhost/MyApp/PDF/File.pdf")

You made need to create a virtual directory pointing to the phyisical path.

0 comments:

Post a Comment