How to take snapshot (screenshot) using (C#, VB) - ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

How to take snapshot (screenshot) using (C#, VB)

Introduction: In this article I will explain how to take snapshot/screenshot of desktop or a particular open window using (C#, VB)

 take snapshot

Html Markup Of page:
<asp:Button ID="Button1" runat="server" Text="Take ScreenShot" onclick="Button1_Click"/>

Note: - First of all we have to add the reference of System.Windows.Forms library.

C# Code:
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing;

    protected void Button1_Click(object sender, EventArgs e)
        Capture("E:/SS/" + Guid.NewGuid() + "ScreenShot.png");
    public static void Capture(string CapturedScreenShot)
            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
            graphics.CopyFromScreen(5, 5, 5, 5, bitmap.Size);
            bitmap.Save(CapturedScreenShot, ImageFormat.Png);
        catch (Exception ex)

VB Code:
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Windows.Forms

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Capture("E:/SS/" & Convert.ToString(Guid.NewGuid()) & "ScreenShot.png")
    End Sub
    Public Shared Sub Capture(ByVal CapturedScreenShot As String)
            Dim bitmap As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            Dim graphics__1 As Graphics = Graphics.FromImage(TryCast(bitmap, System.Drawing.Image))
            graphics__1.CopyFromScreen(5, 5, 5, 5, bitmap.Size)
            bitmap.Save(CapturedScreenShot, ImageFormat.Png)
        Catch ex As Exception
        End Try

    End Sub

Is this article helpful for you?

If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.


hot to store that taken screenshot on sql database plz help me i want to store taken screenshot into database