How to virus scan a DMG archive in C# .NET Framework
Archive files can be a Pandora’s box of potential threats. To limit your exposure, it’s obviously better to screen out potential threats with a layer of virus scanning. While this would normally be quite an undertaking, today’s tutorial will show you how to do it in minutes instead of hours. Let us get started.
Install the Cloudmersive API client via NuGet by running this command from within package manager’s console.
Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 2.0.3
When that finishes, go ahead and call our 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 );}}}}
Input your file and let the API scan it for you, returning the results shortly thereafter. And that’s really all there is to it. You’re done.