How to virus scan a RAR archive in C# .NET Framework

Worried about all the potential viruses hidden within archive files? You’re not alone. Today we are going to solve that for you with a lightning-quick implementation of virus scanning into your app. How quick? How about less than five minutes.

We will begin by bringing up the console of package manager and pasting in the command shown below. This will install our API client via NuGet.

Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 2.0.3

Moving right along, it’s time to call our function, as you see here.

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 );}}}}

And now the API is going to do all the hard work for us while we sit around and enjoy all the coding time we just saved. Not bad at all.

Image for post
Image for post

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