How to take screenshot programmatically and mail it in C#

You can use this code to save the screenshot when there will be any possibility of error in the application .If the client is using the application developer can ask the client to send the screenshot so that he can know in which page the error was occured

  To take the screenshot

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

  Graphics graphics = Graphics.FromImage(bitmap as Image);

  graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

  bitmap.Save("c:\\screenshot.jpeg", ImageFormat.Jpeg);.

 
To send it through email

public void SendAttachedEmail(string to, string subject, string path)
     {
         //To connect the SMTP server for mailing.
         try
         {
             MailMessage objMailMsg = new MailMessage(EmailSender, to);
            
             objMailMsg.Subject = subject;
             Attachment objAttachment = new Attachment(path);
             objMailMsg.Attachments.Add(objAttachment);
     System.Net.Mail.SmtpClient objSmtpClient = new SmtpClient("192.168.10.1", 25);
             objSmtpClient.Send(objMailMsg);
         }
         catch (Exception ex)
         {
            throw ex;
         }
     }
150 150 Burnignorance | Where Minds Meet And Sparks Fly!