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 ();