How to compress files to create a new zip archive in C# .NET Framework
File compression is an excellent tool to have, but can be a be difficult to implement in C#. That is, if you use the standard method. Today I’m going to show you how to use an API as a shortcut to skip all of the hard work and get straight to the results.
To use our API we will need to install our client; accomplish this by entering this command into the console of Package Manager.
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
Now invoking ZipArchiveZipCreate, the API will create our zip file for us.
using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ZipArchiveZipCreateExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ZipArchiveApi();try{// Compress files to create a new zip archiveObject result = apiInstance.ZipArchiveZipCreate();Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ZipArchiveApi.ZipArchiveZipCreate: " + e.Message );}}}}
Done! Oh so easy. We have a ton of other useful API functions like this one, so take a moment and look through our documentation section. It could save you a lot of time!