How to Take Webpage Screenshot Using C# ?

This article shows you how to take screenshot of website forcefully if timeout event fired.

  • Step 1: Download the Websites Screenshot .Net Component.
  • Step 2: Install it on your computer. You will get the WebsitesScreenshot.dll component in the folder.
  • Step 3: Open your visual studio project, add this dll in your project references and try the following sample code.

The following code sample shows you how to take screenshot of the web page with force property. Some web pages take time to load because some error in the web page. In that case we need to take the screenshot forcefully in the given timeout seconds.

C# .Net Code.

WebsitesScreenshot.WebsitesScreenshot _Obj;
_Obj = new WebsitesScreenshot.WebsitesScreenshot();
//Try to take the screenshot forcefully, if page always timedout.
_Obj.TimeOutSeconds = 20;
_Obj.Force = true;
if (_Obj.CaptureWebpage("http://www.WebsitesScreenshot.com") 
	== WebsitesScreenshot.WebsitesScreenshot.Result.Captured)
{
	Bitmap _Bitmap = null;
	_Bitmap = _Obj.GetImage();
	_Bitmap.Save("c:\\test.jpg");
}
_Obj.Dispose();
	

VB .Net code.

Dim _Obj As WebsitesScreenshot.WebsitesScreenshot
_Obj = New WebsitesScreenshot.WebsitesScreenshot()
'Try to take the screenshot forcefully, if page always timedout.
_Obj.TimeOutSeconds = 20
_Obj.Force = True
If _Obj.CaptureWebpage("http://www.WebsitesScreenshot.com") _
	= WebsitesScreenshot.WebsitesScreenshot.Result.Captured Then
	Dim _Bitmap As Bitmap = Nothing
	_Bitmap = _Obj.GetImage()
	_Bitmap.Save("c:\test.jpg")
End If
_Obj.Dispose()