[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

webBrowser thumbnails

Hello, I am using this code on my site to capture website thumbnails.

   private void _GetScreenShot()
        {
            WebBrowser webBrowser = new WebBrowser();
            webBrowser.ScrollBarsEnabled = false;
            DateTime time = DateTime.Now;
            webBrowser.Navigate(url);
            webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
            while (true)
            {
                Thread.Sleep(0);
                TimeSpan elapsedTime = DateTime.Now - time;
                if (elapsedTime.Seconds >= timeout)
                {
                    mre.Set();
                }
                Application.DoEvents();
            }


        }
        private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowser webBrowser = (WebBrowser)sender;
            webBrowser.ClientSize = new Size(this.width, this.height);
            webBrowser.ScrollBarsEnabled = false;
            bmp = new Bitmap(webBrowser.Bounds.Width, webBrowser.Bounds.Height);
            webBrowser.BringToFront();
            webBrowser.DrawToBitmap(bmp, webBrowser.Bounds);
            Image img = bmp.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero);
            string fileName = url.Replace("http://", "") + ".jpg";
            fileName = System.Web.HttpUtility.UrlEncode(fileName);
          if (absolutePath != null && !File.Exists(absolutePath + fileName))
          {
              img.Save(absolutePath + fileName);
          }  
            bmp = (Bitmap)img;          
            webBrowser.Dispose();
          if (mre != null)
              mre.Set();
        }

        public void Dispose()
        {
            if (bmp != null) this.bmp.Dispose();
        }


I am having an issue with serveral snapshots for sites like yahoo, facebook and several others.  I found the problem to be that the web page sets the focus to something on the page.   In yahoo.com for instance the focus is set to the search box onload using this line of code "document.sf1.p.focus();" .

 Without just this line of code the snapshot works great, with it the snapshot comes up blank.  Any ideas on how to fix this?  Thanks Very Much,

Greg
0
grogo21
Asked:
grogo21
1 Solution
 
Michel PlungjanIT ExpertCommented:
Can you use this article?

http://support.microsoft.com/kb/199155

or overwrite the onLoad of the page?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now