Hi,
Just stumbled across this bit of code and need assistance please.
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
Ive tried to replicate this with custom code but to no avail!?
Im aware SHDocVw is the using, is InternetExplorer a static class?
and why SHDocVw.InternetExplorerClass(); at the end - and not the same as the first part of code ie SHDocVw.InternetExplorer?
Thanks
Steve
Loading

VulpesRank #55 · 29.2K reputationPosted May 27, 2011, 10:08 AM EDT
I think I'm right in saying that InternetExplorer is an interface and InternetExplorerClass is a class which implements this interface and so you can assign it to an interface variable.
Although it doesn't look like it will, this should also work:
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
This is because there's both a class and an interface called InternetExplorer and whilst COM can deal with the name duplication, .NET cannot. So the class is hidden in the object browser but is actually instantiated behind the scenes when you 'new up' the interface.
Excel has a similar state of affairs with its Application object (see http://www.c-sharpcorner.com/Forums/Thread/115867/instanciating-an-interface-excel-application.aspx).
Suthish NairRank #92 · 22.8K reputationPosted May 27, 2011, 8:50 AM EDT
msdn forum
Steve7 reputationPosted May 27, 2011, 9:38 AM EDT
The code as requested is below:-
using SHDocVw;
public void OpenBrowser(string url)
{
object o = null;
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
IWebBrowserApp wb = (IWebBrowserApp) ie;
wb.Visible = true;
wb.Navigate(url, ref o, ref o, ref o, ref o);
}
Its the SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass(); statement thats throwing me?
Thanks
Suthish NairRank #92 · 22.8K reputationPosted May 27, 2011, 9:41 AM EDT
Steve7 reputationPosted May 27, 2011, 9:47 AM EDT
Steve7 reputationPosted May 27, 2011, 10:11 AM EDT
So how is SHDocVw.InternetExplorerClass(); possible, ie the SHDocVw listed before InternetExplorerClass?
Suthish NairRank #92 · 22.8K reputationPosted May 27, 2011, 10:11 AM EDT
Its working for me in web application... using VS2010..
check the attachment..
VulpesRank #55 · 29.2K reputationPosted May 27, 2011, 10:14 AM EDT
It's actually unnecessary here as you have the following line in your program:
using SHDocVw;
Suthish NairRank #92 · 22.8K reputationPosted May 27, 2011, 10:18 AM EDT
- Right click the offending assembly that you added in the solution explorer (In my case SHDocVw)
- Click properties.
- And there should be the option there for Embed Interop Assembly.
- Set it to False
The error goes, can you try now.Am trying this library first time, so no idea what it does.
Needs to do find an msdn article..
Suthish NairRank #92 · 22.8K reputationPosted May 27, 2011, 10:27 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 27, 2011, 10:37 AM EDT
There was never any doubt that the code would work :)
Suthish NairRank #92 · 22.8K reputationPosted May 27, 2011, 10:42 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 28, 2011, 2:05 AM EDT
The only explanation of the difference that I have found is that InternetExplorerClass is sometimes needed to avoid use of the InternetExplorer name that is used elsewhere. I forget what that elsewhere is but I know I have seen in the MSDN that there is an explanation.
Steve, I don't know what more you need to do but my Introduction to Web Site Scraping might help too.