foo-baar
foo-baar

Reputation: 1104

Enabling a user to download a file

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.

Upvotes: 4

Views: 2206

Answers (2)

foo-baar
foo-baar

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

Related Questions