Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,


I have an .aspx page. In that i render 10 different reports using ajax update panel and Timer control. Now, i would like to capture content of a website on regular interval by specifying the URL(www.mysite.com/report.aspx). I am able to do this, but if my page has an ajax call i am unable to do that.

I tried the following:
C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;

class Program
{
    [STAThread]
    static void Main()
    {
        int width = 800;
        int height = 600;

        using (WebBrowser browser = new WebBrowser())
        {
            browser.Width = width;
            browser.Height = height;
            browser.ScrollBarsEnabled = true;

            // This will be called when the page finishes loading
            browser.DocumentCompleted += Program.OnDocumentCompleted;

            browser.
            browser.Navigate("www.google.com/");

            // This prevents the application from exiting until
            // Application.Exit is called
            Application.Run();
        }
    }

    static void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        // Now that the page is loaded, save it to a bitmap
        WebBrowser browser = (WebBrowser)sender;

        using (Graphics graphics = browser.CreateGraphics())
        using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height, graphics))
        {
            Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            browser.DrawToBitmap(bitmap, bounds);
            bitmap.Save("screenshot.bmp", ImageFormat.Bmp);
        }

        // Instruct the application to exit
        Application.Exit();
    }
}
Posted

 
Share this answer
 
Comments
Prasad Avunoori 27-May-14 23:13pm    
Thank you Prasad,
It's capturing only once, but i want to capture for every 10 seconds and my website has Timer control which displays 10 different reports.
 
Share this answer
 
Comments
Prasad Avunoori 27-May-14 7:27am    
Thanks for the reply Awadh.
It's only capture the desktop not the specific website's content. I want to capture website's content.
 
Share this answer
 
Comments
Prasad Avunoori 27-May-14 23:13pm    
Thank you Javed,
It's capturing only once, but i want to capture for every 10 seconds and my website has Timer control which displays 10 different reports.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900