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

Cloudmersive
1 min readMar 1, 2020

--

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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet