[Import] response. writefile file garbled Solution

Source: Internet
Author: User

String clientfilename = httputility. urlencode (clientfilename, system. Text. encoding. utf8 );

Clientfilename = clientfilename. Replace ("+", "% 20 ″);

Response. Clear ();
Response. clearheaders ();
Response. Buffer = false;
Response. appendheader ("content-disposition", "attachment; filename =" + clientfilename );

// Response. appendheader ("Content-Length", Fi. length. tostring ());
Response. contenttype = "application/MSWord ";
Response. writefile (filepath );
Response. Flush ();
Response. End ();
Clientfilename = clientfilename. replace ("+", "% 20"); this can solve the problem that the Chinese file name contains spaces, after urlencode encoding, the space in the file name will be converted to + (+ to % 2b), but the browser cannot understand the plus sign as a space, so the file downloaded from the browser, the space is changed to the plus sign;
Solution: After urlencode, replace "+" with "% 20" because the browser converts % 20 to a space.

I thought we could solve the file name garbled during the download, but it still didn't work. My colleague finally helped me solve the problem. It turned out to be

Clientfilename: the file name variable is in Chinese, and it is passed from another page.

Note: use URLs as few as possible to transmit file names. The URL transmission file name will indeed cause inaccurate transmission content, or relatively reliable transmission ID and so on.

This is the problem .. Dizzy ..

Original link: http://aspx1314.cn /? P = 300. Please specify the original address for reprinting. Thank you.

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.