Download an image

  • Thread starter Thread starter Steph
  • Start date Start date
S

Steph

Hi,

I have a button and the code-behind:
Response.ContentType = "image/JPEG";
Response.WriteFile("c:\\Temp\\pc.jpg");

When i click on the button, the image is displayed in a new self-blank page.
Instead of displaying the image, i need the dialog box which propose to
"download the file" to the local computer.

Is there a way to do this ?

Thanks !
 
Not really,

Browsers understand the image/JPEG content type and tries to render it,

For other types of content it would offer the dialog,

best bet is to open the file in a new window with the text "right click
on the image to save"
 
Thanks for your (quick) answer !
And if i use something different than Response.WriteFile ?

Thanks.
 
OK, here is how you can do it

(sorry its in C#)

Response.AddHeader("Content-Disposition",
"attachment;filename=137.jpg");
Response.ContentType = "application/octet-stream";
Response.WriteFile(Server.MapPath("files/137.jpg"));
 
Back
Top