can't open pdf file from aspx page

Discussion in 'ASP .Net' started by graphicsxp, May 31, 2006.

  1. graphicsxp

    graphicsxp Guest

    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
     
    graphicsxp, May 31, 2006
    #1
    1. Advertising

  2. graphicsxp

    Ray Booysen Guest

    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/

    graphicsxp wrote:
    > 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
    >
     
    Ray Booysen, May 31, 2006
    #2
    1. Advertising

  3. graphicsxp

    Hans Kesting Guest

    > 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
     
    Hans Kesting, May 31, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl Prothman [MVP]

    Re: Open linked PDF-Files from a PDF-File

    Carl Prothman [MVP], Aug 9, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    481
    Paul Kuebler
    Aug 12, 2003
  2. Paul Kuebler

    Open linked PDF-Files from a PDF-File

    Paul Kuebler, Aug 12, 2003, in forum: ASP .Net
    Replies:
    8
    Views:
    473
    Carl Prothman [MVP]
    Aug 18, 2003
  3. Vikas Kumar
    Replies:
    1
    Views:
    3,661
    Steve C. Orr [MVP, MCSD]
    May 20, 2006
  4. Ricardo Pog
    Replies:
    1
    Views:
    455
    Austin Ziegler
    Mar 26, 2008
  5. Sean Nakasone
    Replies:
    1
    Views:
    400
    Farrel Lifson
    Apr 14, 2008
Loading...

Share This Page