Solution for downloading file garbled characters from the server
Try {string excelName = Request ["excelName"]. toString (); // file path string fileName = Request ["fileName"]. toString (); // The downloaded file name if (! (String. isNullOrEmpty (excelName) | string. isNullOrEmpty (fileName) {Response. charset = "GB2312"; Response. contentEncoding = Encoding. getEncoding ("GB2312"); Response. contentType = "application/vnd. ms-excel "; // Firefox does not need to convert the Chinese file name encoding format if (Request. serverVariables ["http_user_agent"]. toLower (). indexOf ("firefox") =-1 ){ExcelName = HttpUtility. UrlEncode (excelName, System. Text. Encoding. UTF8 );} Response. appendHeader ("Content-Disposition", "attachment; filename =" + excelName); Response. writeFile (fileName); Response. flush (); Response. close () ;}} catch {}
Make sure that the IE browser needs to convert the Chinese file name encoding format, while the firefox browser does not. Otherwise, the downloaded Chinese file name will be garbled.