Alex Rivera | Logout

ICSharpCode.SharpZipLib.Zip.FastZip not zipping files having special characters in their file names

Asked 2010-11-22T13:06:47.417
12

I am using ICSharpCode.SharpZipLib.Zip.FastZip to zip files but I'm stuck on a problem:

When I try to zip a file with special characters in its file name, it does not work. It works when there are no special characters in the file name.

Edit
Report

2 Answers

1

You have to download and compile the latest version of SharpZipLib library so you can use

entry.IsUnicodeText = true;

here is your snippet (slightly modified):

FileInfo file = new FileInfo("input.ext");
using(var sw = new FileStream("output.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
    using(var zipStream = new ZipOutputStream(sw))
    {
        var entry = new ZipEntry(file.Name);
        entry.IsUnicodeText = true;
        zipStream.PutNextEntry(entry);

        using (var reader = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        {
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0)
            {
                byte[] actual = new byte[bytesRead];
                Buffer.BlockCopy(buffer, 0, actual, 0, bytesRead);
                zipStream.Write(actual, 0, actual.Length);
            }
        }
    }
}
answered 2012-12-20T09:17:21.147
0

Possibility 1: you are passing a filename to the regex file filter.

Possibility 2: those characters are not allowed in zip files (or at least SharpZipLib thinks so)

answered 2010-11-22T19:22:23.167

Your Answer