Click here to Skip to main content
Click here to Skip to main content

Capturing Entire Content of an Internet Explorer Window

, 14 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple solution to capture entire HTML code of a web page which is displaying on Internet Explorer

Introduction

Normally when you need to capture the contents of a webpage, it's enough to use .NET WebBrowser and it always works fine but recently I experienced a different situation: webpage data was displaying by using Ajax and JavaScript and because of that, the WebBrowser component could not catch everything and just displayed pre-designed parts of the web page.

As Internet Explorer was able to show everything perfectly, I decided to find a solution in order to catch the real-time content when page is displaying in Internet Explorer. After searching the web and being faced with a small programming error, finally I succeeded in optimizing an available code for this purpose.

That works fine for me so maybe it can be useful for someone else too.

Using the Code

Just open an Internet Explorer window, go to the website you want to capture and then use the following code. To make it easy to understand, I assumed my goal is to assign a textbox with HTML code of a special webpage.
Required references: MSHTML , SHdocVw

using System.Runtime.InteropServices;
using mshtml;
using System.Reflection;
.
.
.

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
string filename;
 foreach (SHDocVw.InternetExplorer ie in shellWindows)
   {filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
    if (filename.Equals("iexplore") && ie.Name.Equals("Internet Explorer") &&
             ie.LocationURL.Equals("http://www.mysite.com"))
                    {   dynamic d = ie;
                        object v = d.Document.ActiveElement.InnerHTML;
                        textBox1.Text = v.ToString();
                    }

License

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

Share

About the Author

Kaveh Yazdi Nezhad
Software Developer
Canada Canada
I'm a computer programmer Have worked within the information technology companies for over 10 years.
 
Object oriented programming, N-Tire architecture, SQL and Oracle stored procedures, HR, Accounting, Banking, Smart card programming, optimizing SQL queries and database structure and also training end-users are some of my experiences .
Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 14 Jun 2014
Article Copyright 2014 by Kaveh Yazdi Nezhad
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid