How to Screenshot a URL in C# .NET Core

Cloudmersive
2 min readApr 23, 2024

We can easily render and screenshot the contents of a URL using a free API with C# code examples.

This will simplify the process of generating static images of work-in-progress websites. It’ll also make it easy for us to check up on suspicious URLs without having to open them ourselves.

We can customize the height and width of our resulting screenshot in our API request, and we can also specify extra loading wait time (e.g., for websites that have more media to load). Our input request can look like the following example:

{
"Url": "string",
"ExtraLoadingWait": 0,
"ScreenshotWidth": 0,
"ScreenshotHeight": 0
}

To structure our API call, we can begin by running the below command to install the .NET Core SDK:

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

After that, we can call the function using the below 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 );
}
}
}
}

To authorize our requests, we’ll need a free Cloudmersive API key. This will allow us to make up to 800 API calls per month with no additional commitments.

That’s all there is to it — no more code required!

--

--

Cloudmersive

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