Content-disposition attachment filename has different results in Firefox and IE

Source: Internet
Author: User

In Firefox, you need to enclose the filename in double quotes to get the name you want, or if you have a space, you will lose the part behind the space.
And IE will turn the space to _, so also need to Httputility.urlpathencode method to deal with the next name.
If Firefox also uses Httputility.urlpathencode to process names, spaces will be replaced with "%20".


1HttpContext.Current.Response.Buffer =true;2 HttpContext.Current.Response.ClearContent ();3 HttpContext.Current.Response.ClearHeaders ();4HttpContext.Current.Response.ContentType ="application/pdf";5 stringDoc1 = System.IO.Path.GetFileNameWithoutExtension (doc) +"_"+ intnewid.tostring () +". pdf";6 7 if(HttpContext.Current.Request.Browser.Browser! ="IE")8HttpContext.Current.Response.AddHeader ("content-disposition","attachment;filename=\ ""+doc1+"\"");9 ElseTenHttpContext.Current.Response.AddHeader ("content-disposition","attachment;filename="+Httputility.urlpathencode (Doc1)); One byte[] buffer=System.IO.File.ReadAllBytes (DOC); AHttpContext.Current.Response.AddHeader ("Content-length", buffer. Length.tostring ()); -HttpContext.Current.Response.BinaryWrite (buffer);

Content-disposition attachment filename has different results in Firefox and IE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.