在Firefox中需要把filename 用双引号包起来,才能得到想要的名字,不然如果含有空格,会丢掉空格后面的部分。
而IE会把空格转为_,因此也需要HttpUtility.UrlPathEncode方法处理下名字。
如果Firefox中也用HttpUtility.UrlPathEncode处理名字,空格将被替换成"%20".
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType 
= "Application/pdf";
string doc1 = System.IO.Path.GetFileNameWithoutExtension(doc) + "_" + intNewID.ToString() + ".pdf";

if(HttpContext.Current.Request.Browser.Browser != "IE")
         HttpContext.Current.Response.AddHeader(
"Content-Disposition""attachment;filename=\"" +doc1+"\"");
else
    HttpContext.Current.Response.AddHeader(
"Content-Disposition""attachment;filename="+ HttpUtility.UrlPathEncode( doc1));
byte[] buffer=System.IO.File.ReadAllBytes(doc);
HttpContext.Current.Response.AddHeader(
"Content-Length", buffer.Length.ToString());
HttpContext.Current.Response.BinaryWrite(buffer);


转:http://www.cnblogs.com/hardrock/archive/2009/09/30/1576709.html

相关文章:

  • 2021-10-16
  • 2021-12-17
  • 2021-10-13
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2021-11-17
  • 2022-01-24
  • 2021-09-15
  • 2021-07-17
  • 2021-10-13
相关资源
相似解决方案