Download file from link

I have a web page using C # where I want users to be able to click a link (or a link or button, I'm not fussy) and the Save As dialog box will appear so that they can upload the file. The file itself is on another server, so I have to use the absolute path (i: \ division \ department \ publicfiles \ filename.pot). Does anyone know how to do this?

I raised a question here, and some people suggested webClient.DownloadFile. In addition, I cannot use this because it requires you to already know where the user wants the file to be downloaded to his computer. Basically, what I'm looking for is what happens when you right-click on a link and select "save as", but do it when you click on the link.

thanks

+4
source share
3 answers

"The file itself is located on another server" it seems to me that it cannot be published on the Internet and, therefore, does not have a URL. Therefore, a simple anchor tag will not work in this case. I think you are looking for Response.TransmitFile() .

When they click on the link, you need to send the file and explicitly specify the content title and content title. Setting the content header on the attachment save dialog will appear. Like (untested):

 Response.ContentType = "application/x-pot"; Response.AppendHeader("Content-Disposition","attachment; filename=filename.pot"); Response.TransmitFile(@"i:\division\department\publicfiles\filename.pot"); Response.End(); 
+4
source

You can do it as follows:

 <a href="http://www.yoursite.com/folders/yourfile.pdf" target="_blank" > click to download file </a> 
+2
source

With HTML5, you can simply use the new download property in the anchor tag.

The code will look something like this:

 <a download href="path/to/the/download/file"> Clicking on this link will force download the file</a> 

It works with the latest version of Firefox and Chrome. Should I mention that I have not tested it in IE ?: P

0
source

All Articles