Generate website screenshots with C#
Below is some sample code to take website screenshots in C#. For a more detailed guide, checkout the readme of our NuGet package.
using System; using System.Collections.Generic; using System.Threading.Tasks; using UrlboxSDK; // This is our package namespace MyProjectNamespace { class Program { static async Task Main() { // We highly recommend storing your Urlbox API key and secret somewhere secure. string apiKey = Environment.GetEnvironmentVariable("URLBOX_API_KEY"); string apiSecret = Environment.GetEnvironmentVariable("URLBOX_API_SECRET"); string webhookSecret = Environment.GetEnvironmentVariable("URLBOX_WEBHOOK_SECRET"); // Create an instance of Urlbox and the Urlbox options you'd like to use Urlbox urlbox = Urlbox.FromCredentials(apiKey, apiSecret, webhookSecret); // Use the builder pattern for fluent options UrlboxOptions options = Urlbox.Options(url: "https://urlbox.com").Build(); // Take a screenshot - The default format is PNG AsyncUrlboxResponse response = await urlbox.TakeScreenshot(options); // This is the URL destination where you can find your finalized render. Console.Writeline(response.RenderUrl); } } }