2

I have code such as this:

string url = "http://en.wikipedia.org/wiki/Earth";
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.Url = new Uri(url);

but after that last line wb.Url is always null.

Also, if the last line is replaced with:

wb.Navigate(url);

wb.Url and wb.Document are always null. What is going on here? This is the same exact code as in documentation, but it's not working.

I also tried to use SHdocVw:

object o = null;
InternetExplorer ie = new InternetExplorer();
IWebBrowser2 wb1 = (IWebBrowser2)ie;
wb1.Navigate(url, ref o, ref o, ref o, ref o);
HtmlDocument htmlDoc = (HtmlDocument) wb1.Document;
HtmlElementCollection children = htmlDoc.All;

but the wb1.Document returns an E_FAIL HRESULT.

Any help would be appreciated--I'm brand new to C#.

Thanks,
Tyler

Votes + Comments
well posed question
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
1

>but after that last line wb.Url is always null.

That's true. It will remains null till document is not completely rendered.

private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Url = new Uri("http://en.wikipedia.org/wiki/Earth");
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
        }

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            MessageBox.Show(webBrowser1.Url.ToString());

        }
Votes + Comments
Good, as always :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.