How to virus scan a DOCX Document in C# .NET Framework

I won’t lie to you, virus scanning in C# is a long and difficult process. Don’t worry about that, though, as we’ve already done this work for you. It’s ready to go in a handy API. Let me show you how to set it up.

To start off with, we should install our client using this command for package manager.

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

Wait for that to finish, then invoke our virus scanning function.

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

The API will now scan our file for over 17 million virus definitions, which are constantly being update via cloud. Not bad.

Image for post
Image for post

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