473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

File download link does nothing

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
Nov 18 '05 #1
3 1779
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" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
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" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #3
Thanks, Ken. I'll give it a shot!

- John

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
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" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Navin | last post by:
hi, i am using the follwoing code to write a recordset to a csv file 'fcreateFile -file system object Do While Not oRs.EOF fcreateFile.Write(oRs.GetString(,1000,",",vbcrlf,"")) 'Write Login...
3
by: BOHICA | last post by:
I would like on my page when users click one of my mp3 files for the dialog box to pop up so they can choose to save the file to disk instead of trying to open through IE, but the dang thing won't...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
2
by: mhadi | last post by:
Hello Please Help me!! The big bossman is screaming in my ear, I am only devloper of dotnet in my software house and know only to develop widows based application !! My boss wan't me to...
4
by: MW de Jager | last post by:
Hi I want to make a download link on my ASP page, however if I use a Hyperlink, this just tries to open the file in the browser and does nothing if the file is of an unknown type. If I right...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
6
by: Daniel Padron | last post by:
Ok. Maybe I shouldnt post such basic questions here in such an advanced group but my high school programming teacher wont answer any questions outside of his curriculum :( My goal is create a...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
3
colinod
by: colinod | last post by:
I am trying to get my site to download mp3 files without having to right click - save as on a link. I have found this code, which works as long as the file names are short, if they get a bit long it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.