1

Trying to create a zip file in UWP using Ionic zip library. I manually added the Ionic.Zip.dll into the project. After doing that the below code gave an exception.

using (ZipFile zip = new ZipFile()) -------------> Exception on this line
            {

                zip.Password = "password";                
                zip.AddFile(file.Name);
                zip.Save();
            }

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.'

Followed the below link on this issue and modified project.json along with the below lines of code: .NET Core doesn't know about Windows 1252, how to fix?

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1252 = Encoding.GetEncoding(437);

But i get the below exception now on the same line. System.TypeLoadException: 'Could not load type 'System.IO.File' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.'

Not really sure whats going wrong. Need help.

Also is there any library available for UWP which helps in setting up a password for the zip file ? DotnetZip and CSharpZip both dont seem to support UWP project type.

Mohammed Aamir K
  • 311
  • 5
  • 17

1 Answers1

1

We can not add Password to the ZipFile by the Ionic zip library. The default System.IO.Compression library also does not have a password property.

We should able to use the third-party NuGet package to add the password, such as the Chilkat.uwp. We can use Zip.SetPassword method to set the password for the zip file.

For example:

Chilkat.Zip zip = new Chilkat.Zip();
bool success;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
string a = localFolder.Path + "\\sample.zip";
success = zip.NewZip(a);
if (success != true)
{
    Debug.WriteLine(zip.LastErrorText);
    return;
}
zip.SetPassword("secret");
zip.PasswordProtect = true;
bool saveExtraPath;
saveExtraPath = false;
StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder assets = await appInstalledFolder.GetFolderAsync("Assets");
string filePath = assets.Path + "\\rainier.jpg";
success = await zip.AppendOneFileOrDirAsync(filePath, saveExtraPath);
bool success2 = await zip.WriteZipAndCloseAsync();
if (success != true)
{
    Debug.WriteLine(zip.LastErrorText);
    return;
}
Debug.WriteLine("Zip Created!");
Jayden
  • 3,276
  • 1
  • 10
  • 14
  • I did already try using this library. Unfortunately it does not do anything for me. Never creates a zip file. I did use the sample code you provided as it is. Didn't do anything. – Mohammed Aamir K Aug 17 '17 at 13:20
  • The API need the path that some path can not be accessed in UWP even you selected by the FilePicker. Please try the path that in your app. While dealing with files or folders in UWP, one important rule is [Skip the path: stick to the StorageFile](https://blogs.msdn.microsoft.com/wsdevsol/2012/12/04/skip-the-path-stick-to-the-storagefile/). – Jayden Aug 18 '17 at 01:36