How to virus scan a ZIP archive in C# .NET Framework
1 min readMar 1, 2020
Virus scanning ZIP archives in C# isn’t nearly as painful as you might think. That is, if you have an API ready-made for the job.
Open your package manager console and run this command to install the virus scanning API client.
Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 2.0.3
Once that’s finished, go ahead and invoke our virus scan function, like this:
using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.VirusScan.Api;using Cloudmersive.APIClient.NET.VirusScan.Client;using Cloudmersive.APIClient.NET.VirusScan.Model;namespace Example{public class ScanFileExample{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 ScanApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Scan a file for virusesVirusScanResult result = apiInstance.ScanFile(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ScanApi.ScanFile: " + e.Message );}}}}
Alright, we are finished. Seriously, it’s just that easy.