File download link does nothing

Discussion in 'ASP .Net' started by John Spiegel, Apr 21, 2004.

  1. John Spiegel

    John Spiegel Guest

    Hi all,

    I'm trying to do something simple here...just provide a link from which a
    user can download a file. I'm using Server.MapPath() in my codebehind to
    find out physically where the file is then binding that in the aspx page
    like so...

    if (!IsPostBack)
    {
    Session["DownloadPath"] = Server.MapPath(@"Downloads");
    Page.DataBind();
    }

    <A href='<%# @"file:///" + Session["DownloadPath"].ToString() +
    @"\MyFile.pdf" %>'>
    Acrobat&nbsp;PDF</A>

    It works in development but, of course, when I drop it on the web server
    (hosted on one of those cheap $8 / mo. services), nothing happens when I
    click the link. Hovering over the link displays what looks viable to me:

    "file:///d:/accounts/ouraccount/downloadfolder/MyFile.pdf"

    but nothing happens. Am I missing something in my process or is it likely
    an issue to take up with the hosting company?

    TIA,

    John
     
    John Spiegel, Apr 21, 2004
    #1
    1. Advertising

  2. John Spiegel

    John Spiegel Guest

    One ammendment, it now appears that the link is indicating "page not
    available" rather than not responding at all to a click. (I don't think it
    was doing this in testing a couple days ago).

    - John

    "John Spiegel" <> wrote in message
    news:OCQ$...
    > Hi all,
    >
    > I'm trying to do something simple here...just provide a link from which a
    > user can download a file. I'm using Server.MapPath() in my codebehind to
    > find out physically where the file is then binding that in the aspx page
    > like so...
    >
    > if (!IsPostBack)
    > {
    > Session["DownloadPath"] = Server.MapPath(@"Downloads");
    > Page.DataBind();
    > }
    >
    > <A href='<%# @"file:///" + Session["DownloadPath"].ToString() +
    > @"\MyFile.pdf" %>'>
    > Acrobat&nbsp;PDF</A>
    >
    > It works in development but, of course, when I drop it on the web server
    > (hosted on one of those cheap $8 / mo. services), nothing happens when I
    > click the link. Hovering over the link displays what looks viable to me:
    >
    > "file:///d:/accounts/ouraccount/downloadfolder/MyFile.pdf"
    >
    > but nothing happens. Am I missing something in my process or is it likely
    > an issue to take up with the hosting company?
    >
    > TIA,
    >
    > John
    >
    >
     
    John Spiegel, Apr 21, 2004
    #2
    1. Advertising

  3. Hi John,

    I'd say you are going about this the wrong way. A hyperlink that uses
    file:// is going to look on the user's system, not the Web server. Obviously
    you don't want that.

    How about using a linkbutton and in the onclick event, fire up a download of
    the file like this (vb code):

    Response.Clear()
    Response.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "application/pdf"
    'Write the file to the browser and end the HTML content
    Response.WriteFile(Server.MapPath(strFilepath))
    Response.End()


    "John Spiegel" <> wrote in message
    news:OCQ$...
    > Hi all,
    >
    > I'm trying to do something simple here...just provide a link from which a
    > user can download a file. I'm using Server.MapPath() in my codebehind to
    > find out physically where the file is then binding that in the aspx page
    > like so...
    >
    > if (!IsPostBack)
    > {
    > Session["DownloadPath"] = Server.MapPath(@"Downloads");
    > Page.DataBind();
    > }
    >
    > <A href='<%# @"file:///" + Session["DownloadPath"].ToString() +
    > @"\MyFile.pdf" %>'>
    > Acrobat&nbsp;PDF</A>
    >
    > It works in development but, of course, when I drop it on the web server
    > (hosted on one of those cheap $8 / mo. services), nothing happens when I
    > click the link. Hovering over the link displays what looks viable to me:
    >
    > "file:///d:/accounts/ouraccount/downloadfolder/MyFile.pdf"
    >
    > but nothing happens. Am I missing something in my process or is it likely
    > an issue to take up with the hosting company?
    >
    > TIA,
    >
    > John
    >
    >
     
    Ken Cox [Microsoft MVP], Apr 21, 2004
    #3
  4. John Spiegel

    John Spiegel Guest

    Thanks, Ken. I'll give it a shot!

    - John

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:...
    > Hi John,
    >
    > I'd say you are going about this the wrong way. A hyperlink that uses
    > file:// is going to look on the user's system, not the Web server.

    Obviously
    > you don't want that.
    >
    > How about using a linkbutton and in the onclick event, fire up a download

    of
    > the file like this (vb code):
    >
    > Response.Clear()
    > Response.ClearContent()
    > Response.ClearHeaders()
    > Response.ContentType = "application/pdf"
    > 'Write the file to the browser and end the HTML content
    > Response.WriteFile(Server.MapPath(strFilepath))
    > Response.End()
    >
    >
    > "John Spiegel" <> wrote in message
    > news:OCQ$...
    > > Hi all,
    > >
    > > I'm trying to do something simple here...just provide a link from which

    a
    > > user can download a file. I'm using Server.MapPath() in my codebehind

    to
    > > find out physically where the file is then binding that in the aspx page
    > > like so...
    > >
    > > if (!IsPostBack)
    > > {
    > > Session["DownloadPath"] = Server.MapPath(@"Downloads");
    > > Page.DataBind();
    > > }
    > >
    > > <A href='<%# @"file:///" + Session["DownloadPath"].ToString() +
    > > @"\MyFile.pdf" %>'>
    > > Acrobat&nbsp;PDF</A>
    > >
    > > It works in development but, of course, when I drop it on the web server
    > > (hosted on one of those cheap $8 / mo. services), nothing happens when I
    > > click the link. Hovering over the link displays what looks viable to

    me:
    > >
    > > "file:///d:/accounts/ouraccount/downloadfolder/MyFile.pdf"
    > >
    > > but nothing happens. Am I missing something in my process or is it

    likely
    > > an issue to take up with the hosting company?
    > >
    > > TIA,
    > >
    > > John
    > >
    > >

    >
     
    John Spiegel, Apr 22, 2004
    #4
    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. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,667
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  2. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    947
    Kevin Spencer
    May 17, 2005
  3. Liyue Yang

    The Download Link Does NOT Work, Can You Email the File??

    Liyue Yang, Dec 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    129
    Liyue Yang
    Dec 15, 2005
  4. Devin Jeanpierre
    Replies:
    2
    Views:
    531
    Devin Jeanpierre
    Feb 14, 2012
  5. Replies:
    0
    Views:
    103
Loading...

Share This Page