How to validate a GZIP Archive File in C# .Net Framework

Cloudmersive
2 min readJul 29, 2020

--

File validation is an important step toward saving yourself from the massive headaches that can be caused by corrupted or mislabeled files. This is especially true when dealing with archives, as they tend to multiply the effects as well as the potential chance. Setting up this type of archive validation from within C# is actually a pretty tall order, and would normally require a large time investment to get running. Luckily for you, today’s post will have you set up in no time.

We will first install our package using the NuGet console:

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

Next we will go ahead and call our GZIP/GZ validation method from that library:

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 ValidateDocumentGZipValidationExample{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 GZip Archive file (gzip or gz)DocumentValidationResult result = apiInstance.ValidateDocumentGZipValidation(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ValidateDocumentApi.ValidateDocumentGZipValidation: " + e.Message );}}}}

And really, that’s all that you have to do. Within this library, there are numerous other validation functions that cover other archive formats, as well as different document types.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet