Response.AddHeader(QUOT;内容处置")在IE6不打开文件 [英] Response.AddHeader("Content-Disposition") not opening file in IE6

查看:227
本文介绍了Response.AddHeader(QUOT;内容处置")在IE6不打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Response.AddHeader(内容处置,附件;文件名=+ Server.HtmlEn code(文件名));弹出一个打开/保存文件'为用户对话,使他们能够在自己的本地计算机上下载文件。

这是在IE7中正常工作很好,但在IE6的文件不在打开/保存文件对话框中的打开按钮打开时,用户点击。我通过网络去发现
Response.AddHeader(内容处置,内联;文件名=+ Server.HtmlEn code(文件名));
应提供的工作,在IE6,其工作正常。

但问题是最可以在浏览器中打开的文件打开的页面本身..即邮件页面上的用户,然后点击下载打开有一个图像文件,,我需要它在另一个窗口中打开IE7的情况下,我能做些什么......其他文件无法在库巴与系统,即(的Word,Excel等)。

当前应用程序打开打开

请建议坚持使用同样的code两个独立实体的方法...的$ C C I采用的是这里....

  Response.AddHeader(内容处置,附件;文件名=+文件名);
Response.AddHeader(内容长度,file.Length.ToString());
Response.ContentType = ReturnExtension(file.Extension.ToLower());
Response.TransmitFile(file.FullName);
到Response.End(); 私人字符串ReturnExtension(字符串fileExtension)
    {
        开关(fileExtension)
        {
            案名.txt:
                回归text / plain的;
            案例名为.doc:
                返回应用程序/ MS-词;
            案的.xl​​s:
                返回应用程序/ vnd.ms-EXCEL;
            案例符.gif:
                返回到图像/ GIF;
            案.JPG:
            案JPEG:
                返回到图像/ JPEG;
            案.BMP:
                返回到图像/ BMP
            案.WAV:
                返回音频/ WAV
            案.PPT:
                返回应用程序/ mspowerpoint
            案.DWG:
                返回到图像/ vnd.dwg
            默认:
                返回应用程序/八位字节流;
        }
    }


解决方案

我发现我们要阅读的内容和使用缓冲区和二进制写在IE 6中打开文件在IE 6中的问题,,在code下面工作正常,我在IE6

 的FileStream的SourceFile =新的FileStream(使用Server.Mappath(@文件名),FileMode.Open);
浮文件大小;
文件大小= sourceFile.Length;
字节[] =的getContent新的字节[(INT)文件大小]
sourceFile.Read(的getContent,0,(int)的sourceFile.Length);
sourceFile.Close();
Response.ClearContent();
Response.ClearHeaders();
将Response.Buffer =真;
Response.ContentType = ReturnExtension(file.Extension.ToLower());
Response.AddHeader(内容长度,getContent.Length.ToString());
Response.AddHeader(内容处置,附件;文件名=+文件名);
Response.BinaryWrite(的getContent);
Response.Flush();
到Response.End();

I'm using Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.HtmlEncode(FileName)); to pop a 'open/save file' dialog for the users, so that they can download an file on to their local machines.

This is working good normally in IE7,But on IE6 the file is not opening when user click on the open button in 'open/save file' dialog. I gone through the net and found that Response.AddHeader("Content-Disposition", "inline; filename="+Server.HtmlEncode(FileName)); should be provide to work that in IE6,and its works fine..

But the issue is most of the files that can open in browser opens on the page itself.. ie user on a mail page and click download an image file it opens there,, i need it to open in another window as in case of IE7 what can i do... other files that cannot open in bowser open with current application in system ie(word,excel etc)..

please suggest a method to stick with same code for both IEs... The Code i used is 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 the problem in IE 6 we have to read the content and use buffers and binary write to open file in IE 6,, the code below works fine for 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();

这篇关于Response.AddHeader(QUOT;内容处置")在IE6不打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆