简体   繁体   中英

Missing file when zip

I'm using Ionic.zip to zip a bunch of files. This is my code to add those file into the zip.

ZipFile zip = new ZipFile();
foreach (string filepath in listoffile) //5 files
{                             
     zip.AddFile(filepath, "");
}
zip.Save(mypath + "attachment.zip");

When I check the number of file in the zip it show 5, but when I open the zip file it only have 4 files inside and missing the file that contain chinese character in the filename. I try multiple time and different file, the missing of file only happen when the file contain chinese character in it. Is there anyway that I can do to solve this problem?

This looks to be a bug or limitation in , which may be best addressed by logging an issue with wherever you got it from; however, a workaround might be: don't use that - the following works fine with the inbuilt .NET types (on some frameworks you might need to add a package reference to System.IO.Compression ). It is a bit more manual, but: it works.

    using (var output = File.Create("attachment.zip"))
    using (var zip = new ZipArchive(output, ZipArchiveMode.Create))
    {
        foreach (var file in listoffile)
        {
            var entry = zip.CreateEntry(file);
            using (var source = File.OpenRead(file))
            using (var destination = entry.Open())
            {
                source.CopyTo(destination);
            }
        }
    }

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