Reputation: 465
I'm working with a project that performs downloading in C#/Asp.Net, and the files may contain Chinese characters in the filename. 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 ????
or ____
. How I can make the ZipFile
keep the non-ASCII characters of the file name intact?
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);
}
Upvotes: 2
Views: 1814
Reputation: 1587
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.
Upvotes: 4