简体   繁体   中英

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. 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);
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM