How to Block Malicious Uploads in C# .Net Framework

Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 3.0.3
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 ScanFileAdvancedExample{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.var allowExecutables = true;  // bool? | Set to false to block executable files (program code) from being allowed in the input file.  Default is false (recommended). (optional)var allowInvalidFiles = true;  // bool? | Set to false to block invalid files, such as a PDF file that is not really a valid PDF file, or a Word Document that is not a valid Word Document.  Default is false (recommended). (optional)var allowScripts = true;  // bool? | Set to false to block script files, such as a PHP files, Pythong scripts, and other malicious content or security threats that can be embedded in the file.  Set to true to allow these file types.  Default is false (recommended). (optional)var allowPasswordProtectedFiles = true;  // bool? | Set to false to block password protected and encrypted files, such as encrypted zip and rar files, and other files that seek to circumvent scanning through passwords.  Set to true to allow these file types.  Default is false (recommended). (optional)var restrictFileTypes = restrictFileTypes_example;  // string | Specify a restricted set of file formats to allow as clean as a comma-separated list of file formats, such as .pdf,.docx,.png would allow only PDF, PNG and Word document files.  All files must pass content verification against this list of file formats, if they do not, then the result will be returned as CleanResult=false.  Set restrictFileTypes parameter to null or empty string to disable; default is disabled. (optional)try{// Advanced Scan a file for virusesVirusScanAdvancedResult result = apiInstance.ScanFileAdvanced(inputFile, allowExecutables, allowInvalidFiles, allowScripts, allowPasswordProtectedFiles, restrictFileTypes);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ScanApi.ScanFileAdvanced: " + e.Message );}}}}

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Salesforce SOQL

Why I decided to study Software Engineering.

Screenshot a URL in Swift

My 5-year journey(so far) in the tech industry

Aldrin Week in Review

Create secured connection via ssh to AWS Lightsail instance

Wrote a Discord Bot in Python, and Loved It!

Harbor — secure shelter for your Dockers from VMWare

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
Cloudmersive

Cloudmersive

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

More from Medium

How to make custom command in linux

BasGit commands for Testers

Sign your commits on Github

Enumerating active directory using C#