Solution to file name garbled during File Download

Source: Internet
Author: User

Response. addheader ("content-disposition", "attachment; filename =" + system. Web. httputility. urlencode (file. Name, system. Text. encoding. utf8 ));
The Code is as follows:
String filename = request. querystring ["filepath"]. Trim (). Split ('/') [1]; // file name saved by the client

String filepath = server. mappath ("../sysfiles/reportfiles/" + request. querystring ["filepath"]. Trim (); // path

Fileinfo = new fileinfo (filepath );
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. addheader ("content-disposition", "attachment; filename =" + server. urlencode (filename ));
Response. addheader ("Content-Length", fileinfo. length. tostring ());
Response. addheader ("content-transfer-encoding", "binary ");
Response. contenttype = "application/octet-stream ";
Response. contentencoding = system. Text. encoding. getencoding ("gb2312 ");
Response. writefile (fileinfo. fullname );
Response. Flush ();
Response. End ();

However, when a file is downloaded and saved, if the file name contains Chinese characters, the number of Chinese characters cannot exceed 14. Otherwise, the following situations may occur:
The three major share markets of the sales and conversion table are France (200804202242562.16.xls
By the way, the Code is also posted:
<Asp: repeater id = "repdown" runat = "server">
<Itemtemplate>
<Span>
<% # Databinder. eval (container. dataitem, "FILENAME") %>
</Span> <a href = '<% # "downfile. aspx? Name = "+ server. urlencode (databinder. eval (container. dataitem, "FILENAME "). tostring () + "& Path =" + databinder. eval (container. dataitem, "filepath") %> 'target = "_ Self">
Download </a> <br>
</Itemtemplate>
</ASP: repeater>
==========================================================

/* Download writefile */

Fileinfo = new fileinfo (server. mappath (PATH ));
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (name ));

Response. addheader ("Content-Length", fileinfo. length. tostring ());
Response. addheader ("content-transfer-encoding", "binary ");
Response. contenttype = "application/octet-stream ";
Response. contentencoding = system. Text. encoding. getencoding ("gb2312 ");
Response. writefile (fileinfo. fullname );
Response. Flush ();
Response. End ();

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.