处置“)不在IE6中打开文件

我正在使用Response.AddHeader(“Content-Disposition”,“attachment; filename =”+ Server.HtmlEncode(FileName)); 弹出用户的“打开/保存文件”对话框,以便他们可以将文件下载到本地机器上。

这在IE7中正常运行良好,但在IE6上,当用户单击“打开/保存文件”对话框中的打开按钮时,文件不会打开。 我经历了网络,发现Response.AddHeader(“Content-Disposition”,“inline; filename =”+ Server.HtmlEncode(FileName)); 应该提供在IE6中工作,并且其工作正常。

但问题是,可以在浏览器中打开的大多数文件打开在页面本身..即在邮件页面上的用户,并点击下载一个图像文件,它打开那里,我需要它在另一个窗口打开,如在IE7的情况下我能做些什么...其他文件无法打开bowser打开系统中的当前应用程序ie(word,excel等)..

请建议一种方法来坚持使用相同的代码为两个IE ...我使用的代码是在这里....

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";
        }
    }

我发现在IE 6中的问题,我们必须阅读的内容和使用缓冲区和二进制写入在IE 6中打开文件,下面的代码在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.ContentType = "application/octet-stream";
链接地址: http://www.djcxy.com/p/46823.html

上一篇: Disposition") not opening file in IE6

下一篇: docx file doesnt open in browser with content disposition inline in IE 8