File download link does nothing

  • Thread starter Thread starter John Spiegel
  • Start date Start date
J

John Spiegel

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
 
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
 
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()
 
Thanks, Ken. I'll give it a shot!

- John

Ken Cox said:
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 said:
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
 
Back
Top