zoukankan      html  css  js  c++  java
  • content-disposition attachment filename 在Firefox和IE中得到不同的结果

    
    

    在Firefox中需要把filename 用双引号包起来,才能得到想要的名字,不然如果含有空格,会丢掉空格后面的部分。
    而IE会把空格转为_,因此也需要HttpUtility.UrlPathEncode方法处理下名字。
    如果Firefox中也用HttpUtility.UrlPathEncode处理名字,空格将被替换成"%20".


    1
    HttpContext.Current.Response.Buffer = true; 2 HttpContext.Current.Response.ClearContent(); 3 HttpContext.Current.Response.ClearHeaders(); 4 HttpContext.Current.Response.ContentType = "Application/pdf"; 5 string doc1 = System.IO.Path.GetFileNameWithoutExtension(doc) + "_" + intNewID.ToString() + ".pdf"; 6 7 if(HttpContext.Current.Request.Browser.Browser != "IE") 8 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename="" +doc1+"""); 9 else 10 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename="+ HttpUtility.UrlPathEncode( doc1)); 11 byte[] buffer=System.IO.File.ReadAllBytes(doc); 12 HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString()); 13 HttpContext.Current.Response.BinaryWrite(buffer);
  • 相关阅读:
    构建之法阅读笔记01
    软件工程个人作业01
    第一个PSP0级
    java实现课表的增加
    软件工程概论01
    异常处理
    流与文件课件课后作业1计算容量
    第九周课堂测试
    第八周动手动脑
    JAVA项目中常用的异常知识点总结
  • 原文地址:https://www.cnblogs.com/softwaredeveloper/p/4561130.html
Copyright © 2011-2022 走看看