Click here to Skip to main content
15,881,938 members
Articles / Web Development / ASP.NET

Get ASP.NET C# 2.0 Website Thumbnail Screenshot

Rate me:
Please Sign up or sign in to vote.
4.81/5 (34 votes)
22 Jul 2010CPOL1 min read 150.2K   6.2K   70  
How to get a Website/URL thumbnail/screenshot with C#.NET 2.0 in VS 2005.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;


namespace GetWebSiteThumb
{
    public partial class _Default : System.Web.UI.Page
    {
        public DateTime begintime;
        public DateTime stoptime;

        protected void Page_Load(object sender, EventArgs e)
        {
            //todo
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            StartDuration();

            //example as a IHTTPHandler
            ImageBox.ImageUrl = "~/HandlerWSThumb.ashx?url=" + Server.UrlEncode(txtURL.Text).ToLower().ToString() + "&bw=" + txtBW.Text + "&bh=" + txtBH.Text + "&tw=" + txtTW.Text + "&th=" + txtTH.Text;

            StopDuration();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            StartDuration();

            //example as a Class Method
            Bitmap bmp = ClassWSThumb.GetWebSiteThumbnail(txtURL.Text, Int32.Parse(txtBW.Text), Int32.Parse(txtBH.Text), Int32.Parse(txtTW.Text), Int32.Parse(txtTH.Text));
            bmp.Save(Server.MapPath("~") + "/thumbnail.bmp");
            ImageBox.ImageUrl = "~/thumbnail.bmp";

            StopDuration();
        }

        protected void StartDuration()
        {
            begintime = DateTime.Now;
        }

        protected void StopDuration()
        {
            stoptime = DateTime.Now;
            TimeSpan duration = (stoptime - begintime);
            lblTime.Text = duration.ToString();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Web Developer Microsky
Portugal Portugal
Software developer since 1986, as a hobby
and since 1998 as a professional

Currently working for Ogilvy S.A.
(Advertinsing media in portugal)

Comments and Discussions