c# - Response.AddHeader("Content-Disposition") not opening file in IE6 -
i'm using response.addheader("content-disposition", "attachment; filename=" + server.htmlencode(filename)); pop 'open/save file' dialog users, can download file on local machines.
this working in ie7,but on ie6 file not opening when user click on open button in 'open/save file' dialog. gone through net , found response.addheader("content-disposition", "inline; filename="+server.htmlencode(filename)); should provide work in ie6,and works fine..
but issue of files can open in browser opens on page itself.. ie user on mail page , click download image file opens there,, need open in window in case of ie7 can do... other files cannot open in bowser open current application in system ie(word,excel etc)..
please suggest method stick same code both ies... code used here....
response.addheader("content-disposition", "attachment; filename=" +filename); response.addheader("content-length", file.length.tostring()); response.contenttype = returnextension(file.extension.tolower()); response.transmitfile(file.fullname); response.end(); private string returnextension(string fileextension) { switch (fileextension) { case ".txt": return "text/plain"; case ".doc": return "application/ms-word"; case ".xls": return "application/vnd.ms-excel"; case ".gif": return "image/gif"; case ".jpg": case "jpeg": return "image/jpeg"; case ".bmp": return "image/bmp"; case ".wav": return "audio/wav"; case ".ppt": return "application/mspowerpoint"; case ".dwg": return "image/vnd.dwg"; default: return "application/octet-stream"; } }
i have found problem in ie 6 have read content , use buffers , binary write open file in ie 6,, code below works fine me in ie6
filestream sourcefile = new filestream(server.mappath(@"filename"), filemode.open); float filesize; filesize = sourcefile.length; byte[] getcontent = new byte[(int)filesize]; sourcefile.read(getcontent, 0, (int)sourcefile.length); sourcefile.close(); response.clearcontent(); response.clearheaders(); response.buffer = true; response.contenttype = returnextension(file.extension.tolower()); response.addheader("content-length", getcontent.length.tostring()); response.addheader("content-disposition", "attachment; filename=" + filename); response.binarywrite(getcontent); response.flush(); response.end();
Comments
Post a Comment