ASP.NET Introduction to GrabzIt
There are several ways the GrabzIt library can be used to take screenshots in ASP.NET.
The first method is a purely web driven approach were all the code is present in a web application. All of the below examples are written in C# however any ASP.NET language can work with this library.
To get started, first of all create the GrabzItClient class. Pass your application key and application secret from your GrabzIt account to the constructor.
//Create the GrabzItClient class
//Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
private GrabzItClient grabzIt = GrabzItClient.Create("APPLICATION KEY", "APPLICATION SECRET");
Then use one of the SetImageOptions, SetPDFOptions or SetTableOptions methods to request that the GrabzIt service take a screenshot of the URL passed to it.
// To take a image screenshot
// Or to take a PDF screenshot
// Or to capture table(s)
Then call the Save method, passing the URL that you want turned into a screenshot. Assign the ScreenShotComplete event so that we can process the screenshot when it is completed. This method will only work if the code that calls the Save method and the code that accepts the event is in the web application.
protected void btnSubmit_Click(object sender, EventArgs e)
grabzIt.ScreenShotComplete += grabzIt_ScreenShotComplete;
grabzIt.Save(HttpContext.Current.Request.Url.Scheme + "://" +
HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath
//The event method saves the screenshot
protected void grabzIt_ScreenShotComplete(object sender, ScreenShotEventArgs result)
GrabzItFile file = grabzIt.GetResult(result.ID);
Finally configure the web.config so that GrabzIt.ashx points to the handler embedded in the GrabzIt library. If this isn't done properly the event won't be fired.
Remember this callback will not work if your application is located on localhost.
<add verb="*" path="GrabzIt.ashx" type="GrabzIt.Handler, GrabzIt" />
Alternatively the synchonous SaveTo method, this will force your application to wait while the screenshot is created so it should only be used were the Save method cannot be used. Once the screenshot is created it is saved to the file path provided.
string filepath = "images/test.jpg";
There are many more options including; configuring the browser height, browser width, screenshot height, screenshot width, the delay before a screenshot is taken and the image format of the screenshot. For all these options please see the GrabzItClient documentation.