can't open pdf file from aspx page

G

graphicsxp

Hi,
I have the following:
Dim p As String = Server.MapPath("~/Uploads/pdf/test.pdf")
Response.Redirect(p)

The value of p is correct and the file exists. If I enter manually the
value of p into my browser address bar, then the pdf file is properly
opened.

However from the code it doesn't work and although I've added a try
catch block I still can't see the exception. It says:


An exception of type 'System.Exception' occurred in myProject.DLL but
was not handled in user code.

I'm a bit lost there. Can you help ?
Thanks
 
R

Ray Booysen

Copied and pasted from a previous post by Karl:

Response.Redirect throws a ThreadAbordException
intentionally. Technically, Response.Redirect calls Response.End() which
throws the exception.

If you specify true as a 2nd parameter (by default it's false),
Response.End() isn't called, and the page is fully processed before being
redirected.

The real solution to your problem is not to swallow exceptions like you are
doing. You really shouldn't ever catch Exception.

Karl

-- http://www.openmymind.net/
 
H

Hans Kesting

Hi,
I have the following:
Dim p As String = Server.MapPath("~/Uploads/pdf/test.pdf")
Response.Redirect(p)

The value of p is correct and the file exists. If I enter manually the
value of p into my browser address bar, then the pdf file is properly
opened.

However from the code it doesn't work and although I've added a try
catch block I still can't see the exception. It says:

An exception of type 'System.Exception' occurred in myProject.DLL but
was not handled in user code.

I'm a bit lost there. Can you help ?
Thanks

Server.MapPath translates to a *local* (to the server) filepath. The
browser (of the remote user) shouldn't be able to find the file there.
And I don't think you can redirect to a local file, that's why you get
the error.

Get the Request.ApplicationPath ("/" for a root-app, (virtual)
directory without trailing "/" for a non-root app), and append your
"Uploads/pdf/test.pdf" to that for a correct redirect path.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top