How to Screenshot a Website Link in .NET Core

Cloudmersive
2 min readAug 5, 2021

--

Cyber attackers frequently employ fake website links to lure users into their malware trap; all it takes is one careless click to infect your device. In this brief tutorial, we will be sharing an API solution that will allow you to preview the website by generating a PNG screenshot of the URL — JavaScript, HTML5, CSS, and several other advanced features are supported.

To run the API in .NET Core, we first need to install the client:

Install-Package Cloudmersive.APIClient.NETCore.DocumentAndDataConvert -Version 2.2.1

Next, we can call the function by inputting the URL and API key into the following example code:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Model;
namespace Example
{
public class ConvertWebUrlToScreenshotExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ConvertWebApi();
var input = new ScreenshotRequest(); // ScreenshotRequest | Screenshot request parameters
try
{
// Take screenshot of URL
byte[] result = apiInstance.ConvertWebUrlToScreenshot(input);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertWebApi.ConvertWebUrlToScreenshot: " + e.Message );
}
}
}
}

If you need to obtain an API key, you can do so by registering for a free account on the Cloudmersive website; this provides 800 monthly calls across any of our APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet