Hi,
I have referred to the below thread to develop file download with Ajax.
http://www.telerik.com/community/forums/aspnet/ajax/ajax-and-file-download.aspx
The steps are as below:
- Click Download button on default.aspx page which is in an Ajax Panel (RadAjaxPanel1)
- Download Button Even fires
ajm.ResponseScripts.Add("SetContentPage('Download.aspx')");
3. Logic in Download.aspx.cs page processes and user is prompted to Open, Save, Cancel file download.
FileInfo fileInfo = new FileInfo(filepath);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content- Disposition", "attachment; filename=" + fileInfo.Name);
HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.WriteFile(fileInfo.FullName);
4. Done.
The download function is working fine. However, Page is just reloaded instead of download for the first time due to IE download security block.
This can be solved by follow setting as below:
IE Tools -> Internet Options -> Security -> Internet -> Custom Level ->Downloads (Automatic prompting for file downloads) ->Enable.
Unfortunately, the above setting is not a good option. May I know is there any solution to solve the above issue by coding?
Thanks.
Regards,
Teik Ee