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
VulpesPosted May 27, 2011, 2:08 PM
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).
Sam HobbsPosted May 28, 2011, 6:05 AM
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.
Suthish NairPosted May 27, 2011, 2:42 PM
VulpesPosted May 27, 2011, 2:37 PM
There was never any doubt that the code would work :)
Suthish NairPosted May 27, 2011, 2:27 PM
Suthish NairPosted May 27, 2011, 2:18 PM
- 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..
VulpesPosted May 27, 2011, 2:14 PM
It's actually unnecessary here as you have the following line in your program:
using SHDocVw;
Suthish NairPosted May 27, 2011, 2:11 PM
Its working for me in web application... using VS2010..
check the attachment..
StevePosted May 27, 2011, 2:11 PM
So how is SHDocVw.InternetExplorerClass(); possible, ie the SHDocVw listed before InternetExplorerClass?
StevePosted May 27, 2011, 1:47 PM
Suthish NairPosted May 27, 2011, 1:41 PM
StevePosted May 27, 2011, 1:38 PM
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 NairPosted May 27, 2011, 12:50 PM
msdn forum