This is a migrated thread and some comments may be shown as answers.

File Download with Ajax would be encountered problem on IE download security options block.

1 Answer 135 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Teik Ee
Top achievements
Rank 1
Teik Ee asked on 25 Nov 2008, 10:38 AM

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:

  1. Click Download button on default.aspx page which is in an Ajax Panel (RadAjaxPanel1) 
  2. 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 

 

1 Answer, 1 is accepted

Sort by
0
Ewoud
Top achievements
Rank 1
answered on 27 Feb 2009, 02:39 PM
Hi,

Can u, or someone else give me the full example of this code (including the logic in the download.aspx) I thank u for that!!

Regards,
Hans
Tags
Ajax
Asked by
Teik Ee
Top achievements
Rank 1
Answers by
Ewoud
Top achievements
Rank 1
Share this question
or