Hi there!
I've been pulling my hair out for hours trying to figure this out.
I have an iframe with which I want to download a file. It all works fine, but the iframe onload is not called if my Response.ContentType = "APPLICATION/OCTET-STREAM";
My javascript function is as follows:
function DownloadStuff(){
var DownloadSource = "http://Apage.aspx"
var iframe = $("#hiddenDownloader");
if (iframe.attr("id") === undefined) {
$('<iframe />', { id: 'hiddenDownloader', onload:'javascript:alertReady();' }).appendTo('body');
iframe = $("#hiddenDownloader");
}
iframe.attr('src', DownloadSource);
}
function alertReady() {
alert("Ready");
}
My server side code is as follows:
Response.Clear();
Response.CacheControl = "no-cache";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(false);
Response.ExpiresAbsolute = DateTime.Parse("1/1/2000");
Response.Expires = 0;
Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AddHeader("Content-Disposition", "attachment;filename=\"ReportDeck.pptx\"");
byte[] bytes = (byte[])PowerPointFile.Tables[0].Rows[0]["PPTBlob"];
bytes = Compression.DeCompressByteArray(bytes);
Response.OutputStream.Write(bytes, 0, bytes.Length);
If I remove the ContentType and Header the onload is called, but then the file is not downloaded through the save file dialog, but is instead written into the iframe.
Any help is appreciated.
Regards, Byron Cobb.