Adding .NET zip functionality to Xamarin projects
There are various options out there to create zip files in your Xamarin projects and an issue with a 3rd party library gave me the opportunity to seek an alternative. The problem I often run into when relying on a 3rd party and/or open source code is compatibility and in some cases support when running into a bug. On Xamarin.iOS I remember having issues with compatibility and an odd bug likely related to memory consumption. Working on a Xamarin.Android project I didn’t want to rely on native java so I could share code cross-platform and looked for a .NET solution. Microsoft introduced the ZipArchive library in .NET 4.5 and supports Portable Class Libraries.
I put together a simple method called QuickZip with two parameters, string filesToZip and string destinationZipFullPath. Supply an array files you want to include in the zip file and the destination where you want it created. If successful the method will return true if the zip file exists otherwise false. Make sure to add assembly references to System.IO.Compression.dll and System.IO.Compression.FileSystem.dll. The compression level defaults to optimal but also supports Fastest and NoCompression.
Wanted to share a quick way to zip files in your projects that’s supported cross-platform and hope it’s useful.