How to extract Files and Folders from a Zip Archive in C# .NET Framework

Cloudmersive
2 min readApr 18, 2020

--

For today’s quick tutorial, we will be setting up unzipping functionality in C#. This is actually going to be a lot easier than it seems at first glance. We can just skip right over the usual hurdles through effective use of an API. Let’s get straight to it.

To start using the API in question, we will need to install its client. We can do this by running the following command from the console in Package Manager.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

And now that our installation has finished, we simply run the ZipArchiveZipExtract function using the following sample code.

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 ZipArchiveZipExtractExample{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();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Extract, decompress files and folders from a zip archiveZipExtractResponse result = apiInstance.ZipArchiveZipExtract(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ZipArchiveApi.ZipArchiveZipExtract: " + e.Message );}}}}

And that, ladies and gentlemen, is all there is to that. You now have zip extraction and never have to worry about it again. Not bad, right?

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet