I upload the file by going through the .aspx page and return the file
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM"; String Header = "Attachment; Filename=" + sFileName; HttpContext.Current.Response.AppendHeader("Content-Disposition", Header); FileInfo Dfile = new FileInfo(HttpContext.Current.Server.MapPath(sFilePath)); HttpContext.Current.Response.WriteFile(Dfile.FullName); HttpContext.Current.Response.End();
and itβs wonderful.
I want to be able to do this with an async ajax call using jQuery so that the user sees animation with gif spinners during file upload.
$("#showbusy").fadeIn(); $.ajax({ async : true, type: "GET", url: "download.aspx", contentType: "application/text; charset=utf-8", success: function (data) { $("#showbusy").hide(); }, error: function (xmlHttpRequest, textStatus, errorThrown) { $("#showbusy").hide(); } });
If I go directly to the .aspx page, the file will load, but this does not work, if for some reason you make ajax call to this page. I see that the data is being returned to Firebug, but as soon as it finishes loading, it just sits there in memory.
How can I initiate a browser save file dialog after receiving file upload data?
source share