Problematic code segment:
Response. ContentType = ftype; // ftypeis the file suffix, such as. jpg,. txt,. Zip
Response. AddHeader ("Content-Disposition", "attachment; filename =" + fnametype); // fnametypeindicates the full name of the file, for example, file1.jpg // leading to Chinese name garbled characters
String filename = Server. MapPath ("Resource \" + fnametype); // filename is the relative file path
Response. TransmitFile (filename );
Effective solutions to these two problems:
Response. Clear (); // solves the code problem in the TXT file.
Response. ContentType = ftype;
Response. AddHeader ("Content-Disposition", "attachment; filename =" + Server. UrlEncode (fnametype); // solves the problem of garbled Chinese file names
String filename = Server. MapPath ("Resource \" + fnametype );
Response. TransmitFile (filename); www.2cto.com
Response. End (); // solves the code problem in the TXT file.