Response.AddHeader(“Content-Disposition”) not opening file in IE6

前端 未结 2 605
庸人自扰
庸人自扰 2020-12-03 02:06

I\'m using Response.AddHeader(\"Content-Disposition\", \"attachment; filename=\" + Server.HtmlEncode(FileName)); to pop a \'open/save file\' dialog for the users, so that th

相关标签:
2条回答
  • 2020-12-03 02:47

    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();
    
    0 讨论(0)
  • 2020-12-03 02:54

    Try this setting the content type to octet stream:

    Response.ContentType = "application/octet-stream";
    
    0 讨论(0)
提交回复
热议问题