SIGN UP MEMBER LOGIN:    
ARTICLE

Creating an Instance of Internet Explorer in C#

Posted by Gregory Correll Articles | Internet & Web December 19, 2002
I was trying to write a program that opened an instance of Internet Explorer in a separate window, rather than use the Browser control that comes with the .NET platform.
Reader Level:
Download Files:
 

I was trying to write a program that opened an instance of Internet Explorer in a separate window, rather than use the Browser control that comes with the .NET platform.

Unfortunately, it proved almost impossible to find any references to the interfaces necessary to do the job.

This is a very simple program that allows the user to type a URL into a textbox, and then open IE directly to that URL.

This only works with IE4 and above.

The heart of the code is exposing the IWebBrowserApp interface. This interface is located in the SHDocVw.dll, which can be found (on Win2K/Xp) in the System32 directory.

The source code is simple:

using SHDocVw;
public void OpenBrowser(string url)
{
object o = null;
SHDocVw.InternetExplorer ie =
new
SHDocVw.InternetExplorerClass();
IWebBrowserApp wb = (IWebBrowserApp) ie;
wb.Visible =
true;
//Do anything else with the window here that you wish
wb.Navigate(url, ref o, ref o, ref o, ref o);
}

I hope this is useful to others.

Login to add your contents and source code to this article
share this article :
post comment
 

You do that and it likely will NOT work. The code assumes Internet Explorer is installed and functioning properly (i.e. can launch normally, can access websites with no issues, etc.).

Posted by Tom Jackson Dec 16, 2010

Hi, great article. If i uninstall ie from os then it is work?

Posted by Parthesh Mehta Dec 16, 2010

You might need to register mshtml.dll - 


On the Run line, type this and click OK:

regsvr32 C:\WINDOWS\system32\mshtml.dll

Posted by Tom Jackson Sep 11, 2010

If you're talking about actually sending that text to a real printer (not just printing to the screen, i.e. my Response.Write line above), then use this at the end, instead of that line:


LPrintWriter lprint = new LPrintWriter();
lprint.WriteLine(bodytext);
lprint.Close();


Posted by Tom Jackson Sep 11, 2010

Hi Tom,


Can I know where do u actually print the WebDocument??

Posted by Vinod Somavarpu Sep 11, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor