C# How to get current URL from the IE?

后端 未结 1 1820
栀梦
栀梦 2020-12-07 01:34

I want to get the current URL from the IE (.NET 4) . To do so, I added a reference to Microsoft Interner Controls and added the code (from http://omegacoder.com/?p=63)

相关标签:
1条回答
  • 2020-12-07 02:33

    The 2nd error causes the first one. Open the project's References node, select SHDocVw. In the Properties window, change "Embed Interop Types" to false. You will have to deploy the Interop.SHDocVw.dll assembly you'll find the build output directory along with your program.

    EDIT: after researching this error, I found a better way to do this. The issue is that only COM interface types can be embedded, not classes. So avoid using the synthetic XxxxClass wrappers in your code. Make it look like this instead:

            foreach (InternetExplorer ie in new ShellWindows()) {
                //...
            }
    

    Which looks strange, you cannot normally use the new operator on an interface type in the C# language. But is actually supported for COM interfaces.

    0 讨论(0)
提交回复
热议问题