0

I am trying to zip a file or directory in C# using the following snippet of code on a mac that uses DotNetZip. But I get some exceptions below, what am I doing wrong?

using Ionic.Zip;

namespace CSLab
{
   class Program
   {
      static void Main(string[] args)
      {
         using (ZipFile zip = new ZipFile())
         {
            zip.Password = "password";
            zip.AddDirectory("./test");
            zip.Save("a.zip");
         }
      }
   }
}


Unhandled Exception: System.ArgumentException: 'IBM437' is not a 
supported encoding name. For information on defining a custom 
encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name
  at System.Globalization.EncodingTable.GetCodePageFromName(String name)
  at System.Text.Encoding.GetEncoding(String name)
  at Ionic.Zip.ZipFile..ctor()
  at CSLab.Program.Main(String[] args) in 
  bash: line 1: 17217 Abort trap: 6           
  "/usr/local/share/dotnet/dotnet" 
  "/usr../bin/Debug/netcoreapp2.0/CSLab.dll"
user2399453
  • 2,930
  • 5
  • 33
  • 60
  • Does [DotNetZip trouble with coding](https://stackoverflow.com/q/2565414/1115360) help? – Andrew Morton Jan 22 '18 at 18:59
  • The error is very explicit. You have to change the encoding. That's probably configurable using the public properties of ZipFile. go to http://dotnetzip.codeplex.com/SourceControl/latest#Zip/ZipFile.cs and search for "he specification does not describe how to indicate the encoding used" and read the entire comment. –  Jan 22 '18 at 19:04
  • I believe this is dotnet core env? If it is, then you are out luck. DotNetZip is not supported under dotnet core. – Cinchoo Jan 22 '18 at 19:23
  • If DotNetZip is not supported then what is an alternative way to create a password protected zip file? – user2399453 Jan 22 '18 at 20:05
  • @Will I get the same error when I do as per the comment: zip.AlternateEncodingUsage = ZipOption.Always; – user2399453 Jan 22 '18 at 21:28
  • Yes, but you don't specify WHAT encoding to use. If you don't know what "encoding" means in this context, you **need to learn**. Go search for "character encoding". Apparently those a_holes over at Cupertino don't support the default encoding for zip files (IBM437 as it says in the docs I pointed to you) so you need to choose another. UTF-8 is probably the best choice, as it's the standard Unicode encoding. While you used AlternateEncodingUsage, you didn't *specify what encoding to use*. That's what you put in the AlternateEncoding property. –  Jan 23 '18 at 14:24

0 Answers0