开发者

ASHX Image Download on Click

I am using ashx to serve images from a database, is there anyway to have a user click on a link that allows them to download the file on the computer. (IE it shows the Save Dialog) Like you download a file. Is this possible to开发者_高级运维 do?


If you want it to prompt to save make sure you add the following line when creating the response:

context.Response.AppendHeader("Content-Disposition",
    "attachment;filename=" + filename);

This will make the browser treat it like an attachment and prompt with the save dialog.

EDIT: Based on your comment make sure you are building your response correctly:

// set attachment header like above
// then you need to get your file in byte[] form
byte[] dataYouWantToServeUp = GetData();
// you can set content type as well
yourHttpContext.Response.ContentType = "image/jpg";
// serve up the response
yourHttpContext.Response.BinaryWrite(dataYouWantToServeUp);


I think that if the navigator is able to open type of the file you're trying to get, It will open it without asking. If for instants, the file is in zip format, the navigator is not able to open it and will ask you to download it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜