C# / .NET
Take screenshots using C# with our official SDK or plain HTTP requests.
Installation
dotnet add package LambdaShot Or via NuGet Package Manager:
Install-Package LambdaShot Quick Start
using LambdaShot;
var client = new LambdaShotClient("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY");
// Take a screenshot
var screenshot = await client.TakeAsync(new TakeOptions
{
Url = "https://example.com",
Format = "png",
ViewportWidth = 1920,
ViewportHeight = 1080
});
// Save to file
await File.WriteAllBytesAsync("screenshot.png", screenshot); Generate Signed URL
var url = client.GenerateSignedUrl(new TakeOptions
{
Url = "https://example.com",
Format = "png",
BlockAds = true
});
Console.WriteLine(url);
// https://api.lambdashot.com/take?url=...&signature=... Options
var screenshot = await client.TakeAsync(new TakeOptions
{
Url = "https://example.com",
// Output
Format = "png",
ImageQuality = 90,
// Viewport
ViewportWidth = 1920,
ViewportHeight = 1080,
ViewportDevice = "iphone_15_pro",
DeviceScaleFactor = 2,
// Full page
FullPage = true,
FullPageScroll = true,
// Blocking
BlockAds = true,
BlockCookieBanners = true,
BlockTrackers = true,
// Customization
DarkMode = true,
Delay = 2,
WaitForSelector = ".content-loaded"
}); Without SDK (HttpClient)
using System.Net.Http;
using System.Web;
var query = HttpUtility.ParseQueryString(string.Empty);
query["access_key"] = "YOUR_ACCESS_KEY";
query["url"] = "https://example.com";
query["format"] = "png";
query["viewport_width"] = "1920";
using var httpClient = new HttpClient();
var response = await httpClient.GetByteArrayAsync(
$"https://api.lambdashot.com/take?{query}"
);
await File.WriteAllBytesAsync("screenshot.png", response); Video Recording
var video = await client.AnimateAsync(new AnimateOptions
{
Url = "https://example.com",
Scenario = "scroll",
Duration = 10,
Format = "mp4"
});
await File.WriteAllBytesAsync("video.mp4", video); Error Handling
try
{
var screenshot = await client.TakeAsync(new TakeOptions
{
Url = "https://example.com"
});
}
catch (LambdaShotException ex)
{
switch (ex.Code)
{
case "timeout_error":
Console.WriteLine("Screenshot timed out, retrying...");
break;
case "access_key_invalid":
Console.WriteLine("Check your API key");
break;
default:
Console.WriteLine($"Error: {ex.Message}");
break;
}
} ASP.NET Core Integration
// Program.cs
builder.Services.AddSingleton<LambdaShotClient>(sp =>
new LambdaShotClient(
builder.Configuration["LambdaShot:AccessKey"],
builder.Configuration["LambdaShot:SecretKey"]
)
);
// appsettings.json
{
"LambdaShot": {
"AccessKey": "YOUR_ACCESS_KEY",
"SecretKey": "YOUR_SECRET_KEY"
}
}
// Controllers/ScreenshotController.cs
[ApiController]
[Route("api/[controller]")]
public class ScreenshotController : ControllerBase
{
private readonly LambdaShotClient _lambdashot;
public ScreenshotController(LambdaShotClient lambdashot)
{
_lambdashot = lambdashot;
}
[HttpGet]
public async Task<IActionResult> Get([FromQuery] string url)
{
var screenshot = await _lambdashot.TakeAsync(new TakeOptions
{
Url = url,
Format = "png"
});
return File(screenshot, "image/png");
}
} Dependency Injection
// Register as singleton
services.AddSingleton<ILambdaShotClient>(sp =>
new LambdaShotClient(accessKey, secretKey));
// Or use the extension method
services.AddLambdaShot(options =>
{
options.AccessKey = Configuration["LambdaShot:AccessKey"];
options.SecretKey = Configuration["LambdaShot:SecretKey"];
});