Reputation: 1104
I am working on an image gallery, and on the browse image module, I have a download icon. I need it to behave as a download button. When the user clicks on it, they should be presented with save file dialog, or the file should be downloaded using their default browser download set-up.
I tried many ways, but no luck.
The download Icons appear in a Modal-popup and hence all code is wrapped inside UpdatePannel
These images are of different formats (jpeg, gif, tif, psd)
Upvotes: 4
Views: 2206
Reputation: 1104
Finally sorted out with :
A) To download a file at Client Location :
public void downloadFile(string fileName, string filePath)
{
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", fileName));
Response.WriteFile(filePath + fileName);
}
B) Since the function triggering controls(imgDownload
, imgDownloadPsd
) are wrapped under async call : Add this to Page Load :
protected void Page_Load(object sender, EventArgs e)
{ ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(imgDownload);
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(imgDownloadPsd);
}
Upvotes: 0
Reputation: 10347
Look at http://www.codeproject.com/Articles/74654/File-Download-in-ASP-NET-and-Tracking-the-Status-o or Best way to stream files in ASP.NET
Upvotes: 4