[英]ZipFile messes up Chinese characters
I'm working with a project that performs downloading in C#/Asp.Net, and the files may contain Chinese characters in the filename. 我正在使用一个在C#/ Asp.Net中执行下载的项目,文件中可能包含中文字符。 When downloading a single file, the Chinese filename is displayed properly.
下载单个文件时,中文文件名会正确显示。 However, when downloading multiple files in a
ZipFile
, the files inside the folder will have the Chinese characters shown up as ????
但是,当在
ZipFile
下载多个文件时,文件夹中的文件将显示为中文字符????
or ____
. 或
____
。 How I can make the ZipFile
keep the non-ASCII characters of the file name intact? 如何使
ZipFile
保持文件名的非ASCII字符完整?
Here's the multiple file download code: 这是多文件下载代码:
using (ZipFile zip = new ZipFile())
{
// fileList is of type List<string>
zip.AddFiles(fileList, "files");
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposition", "filename=file.zip");
zip.Save(Response.OutputStream);
Response.End();
}
And the code for downloading a single file: 以及下载单个文件的代码:
if (File.Exists(Path))
{
FileInfo fileInfo = new FileInfo(Path);
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/x-download";
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Response.TransmitFile(fileInfo.FullName);
Response.End();
File.Delete(Path);
}
Try this: 尝试这个:
using (ZipFile zip = new ZipFile())
{
zip.ProvisionalAlternateEncoding = System.Text.Encoding.UTF8;
zip.AddFiles(fileList, "files");
It's beacuse DotNetZip use IBM437(Encoding) as default,so you should set appropriate Encoding , like Encoding.UTF8. 这是因为DotNetZip默认使用IBM437(编码),所以你应该设置适当的编码,比如Encoding.UTF8。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.