How to validate a ZIP Archive in C# .Net Framework

Think of file validation as an insurance policy against catastrophic failure at the hands of invalid files down the road. While under normal circumstances this might take quite a while to set up in C#, today’s tutorial will have you up and running in very little time indeed. Let’s get into the details.

Our first step will be to install our client library, which can be accomplished easily enough by opening the Package Manager console and pasting in this command for NuGet:

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

And then we follow that by instancing our API using a free key and then calling the ZIP validation function. Details for this can be seen in this example:

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 ValidateDocumentZipValidationExample{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 ValidateDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Validate a Zip Archive file (zip)DocumentValidationResult result = apiInstance.ValidateDocumentZipValidation(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ValidateDocumentApi.ValidateDocumentZipValidation: " + e.Message );}}}}

And you’re done!

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store