File download link does nothing

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
 
J

John Spiegel

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
 
K

Ken Cox [Microsoft MVP]

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()
 
J

John Spiegel

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
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top