Antivirus File Scanner API in C#

< Back to Guides

C# is a general-purpose, multi-paradigm programming language. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented, and component-oriented programming disciplines. This tutorial is how to check a file for malware using API in .NET C# programming language.

Instructions

  1. Get a free API to use by signing up at FileScanAPI.com and replace REPLACE_ME with your API key.
  2. Update location value in body with url location of your file.
  3. Update callback value in body to your webhook url. We recommend using webhook.site as a callback url during test.

For 2 and 3, you can find this documented at Offical Documentation

 

Check file for malware in ReSharp - NuGet version 107 and higher

var client = new RestClient(new RestClientOptions("https://api.filescanapi.com")
{
    MaxTimeout = -1
});

// Create a POST request to the asynchronous file endpoint
var request = new RestRequest("/v1/file/async", Method.Post)
    .AddHeader("x-api-key", "REPLACE_ME")
    .AddHeader("Content-Type", "application/json");

// Construct the JSON body using verbatim string literals for readability
var body = @"
{
    ""location"": ""https://filescanapi.com/icon.png"",
    ""metadata"": {
        ""filename"": ""demo.png""
    },
    ""callback"": ""https://webhook.site/""
}";

// Add the JSON body to the request
request.AddStringBody(body, DataFormat.Json);
// Execute the request asynchronously and output the response content
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);

 

Anti-virus file scanner for ReSharp - NuGet version 106 and lower

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.filescanapi.com/v1/file/async");
request.Headers.Add("x-api-key", "REPLACE_ME");
var content = new StringContent(@"
{
    ""location"": ""https://filescanapi.com/icon.png"",
    ""metadata"": {
        ""filename"": ""demo.png""
    },
    ""callback"": ""https://webhook.site/""
}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());