473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

WebBrowser DocumentText getting problem ...

I have very strange and stupid problem with .NEt's webBrowser control...

If I do this:
----------------------------------
private void btnGoogle_click(object sender, EventArgs e)

{

webBrowser1.Navigate(http://www.google.com);

}
----------------------------------

and after that try this:

-----------------------------------

string html;

html = webBrowser1.DocumentText.ToString();

------------------------------------

I get error: "The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)"
BUT
If I open Google (or any other page), and if I then click any link in
webBrowser, and after that try to get html content, all works fine...

Is there any way to get HTML content while navigating automaticly (with my
buttons)..

Hope I was clear :)

Thanks in advance.

Electronic.HR
Jun 5 '07 #1
7 18647
The content is fetched in the web browser asynchronously. You should
wait until the downloading is done before you try and access the
DocumentText property. You can do this by subscribing to the
DocumentCompleted event and then getting the text from the document from
there.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"- Electronic.HR -" <el***********@gmail.comwrote in message
news:f4**********@news1.carnet.hr...
>I have very strange and stupid problem with .NEt's webBrowser control...

If I do this:
----------------------------------
private void btnGoogle_click(object sender, EventArgs e)

{

webBrowser1.Navigate(http://www.google.com);

}
----------------------------------

and after that try this:

-----------------------------------

string html;

html = webBrowser1.DocumentText.ToString();

------------------------------------

I get error: "The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)"
BUT
If I open Google (or any other page), and if I then click any link in
webBrowser, and after that try to get html content, all works fine...

Is there any way to get HTML content while navigating automaticly (with my
buttons)..

Hope I was clear :)

Thanks in advance.

Electronic.HR
Jun 5 '07 #2
Hm...good idea.. but it doesn't work either...
I done this
<CODE>
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{

string html;

MessageBox.Show("Document Completed");
html = webBrowser1.DocumentText.ToString();
MessageBox.Show(html);

}
</CODE>
first message box appears, but second one doesn't!
(In this case nothing happens. In this case there's no Exception showing,
but second message box doesn't appear) ?!?
Jun 5 '07 #3
Well, by default, exceptions thrown by event handlers on controls are
swallowed. You will have to wrap in a try/catch block to figure out what
the exception is (you can look at it in the debugger too).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"- Electronic.HR -" <el***********@gmail.comwrote in message
news:f4**********@news1.carnet.hr...
Hm...good idea.. but it doesn't work either...
I done this
<CODE>
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{

string html;

MessageBox.Show("Document Completed");
html = webBrowser1.DocumentText.ToString();
MessageBox.Show(html);

}
</CODE>
first message box appears, but second one doesn't!
(In this case nothing happens. In this case there's no Exception showing,
but second message box doesn't appear) ?!?
Jun 5 '07 #4
When I click on a link in webBrowser, only then DocumentText fills with
content...

What's difference between:
- clicking on a link in webBrowser and
- calling webBrowser1.Navigate(...);

?
Jun 5 '07 #5
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
Well, by default, exceptions thrown by event handlers on controls are
swallowed. You will have to wrap in a try/catch block to figure out what
the exception is (you can look at it in the debugger too).
Try/catch gives no result....no exception..code just continues...
....
Now, when I call webBrowser1.Navigate(...), and watch DocumentText in
debugger after DocumentCompleted event this is what I get:

<DOCUMENT_TEXT>
- DocumentText '((System.Windows.Forms.WebBrowser)(sender)).Docum entText'
threw an exception of type 'System.IO.FileNotFoundException' string
{System.IO.FileNotFoundException}
- base {"The system cannot find the file specified. (Exception from HRESULT:
0x80070002)":null} System.IO.IOException {System.IO.FileNotFoundException}
- FileName null string
- FusionLog null string
- Message "The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)" string

</DOCUMENT_TEXT>

but.. when I click on a link in webBrowser and then look at DocumentText
after DocumentCompleted event i get this:
- DocumentText -it's value is HTML content of a page, and type is
string...all is prefect :-(
I really don't have idea why is this happening...

p.s. Thanks for helping, Nicholas :)


Jun 5 '07 #6
Im only suggesting wrapping the first call in the event handler to the
DocumentText property, not the whole thing. Regardless, if that second line
was not executing, then an exception could be the onlyh reason.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"- Electronic.HR -" <el***********@gmail.comwrote in message
news:f4**********@news1.carnet.hr...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:%2****************@TK2MSFTNGP04.phx.gbl...
> Well, by default, exceptions thrown by event handlers on controls are
swallowed. You will have to wrap in a try/catch block to figure out what
the exception is (you can look at it in the debugger too).

Try/catch gives no result....no exception..code just continues...
...
Now, when I call webBrowser1.Navigate(...), and watch DocumentText in
debugger after DocumentCompleted event this is what I get:

<DOCUMENT_TEXT>
- DocumentText '((System.Windows.Forms.WebBrowser)(sender)).Docum entText'
threw an exception of type 'System.IO.FileNotFoundException' string
{System.IO.FileNotFoundException}
- base {"The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)":null} System.IO.IOException
{System.IO.FileNotFoundException}
- FileName null string
- FusionLog null string
- Message "The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)" string

</DOCUMENT_TEXT>

but.. when I click on a link in webBrowser and then look at DocumentText
after DocumentCompleted event i get this:
- DocumentText -it's value is HTML content of a page, and type is
string...all is prefect :-(
I really don't have idea why is this happening...

p.s. Thanks for helping, Nicholas :)

Jun 5 '07 #7
Hm.. I can't believe.. LOL...

Problem is that webBrowser control MUST be FOCUSED before taking
DocumentText... :)
When I click on a link in browser it get's automaticly focused, that's why I
always got DocumentText when I clicked link..
but When I call navigate, webbrowser doesn't get focused, so i have to focus
it manually before taking DocumentText...

Anyway, thanks a lot for helping! ;)

BR

Jun 5 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lee | last post by:
Hi, I am using the WebBrowser control included with VS2005 to view XML files, and they are being displayed correctly as far as I can tell. The problem I am having is saving these XML files to...
2
by: Lee | last post by:
Hi, I am using the WebBrowser control included with VS2005 to view XML files, and they are being displayed correctly as far as I can tell. The problem I am having is saving these XML files to...
2
by: myzm | last post by:
Hello there, I use webbrowser loading a web page and want to display the html file in a RichtextBox. I find out that the size of the DocumentText is far less than the actual size of the html...
1
by: annieorben | last post by:
I'm trying to view HTML code by examining the .DocumentText property of a web browser. But I can't get any more than 4096 characters to show up. I'm using VB 2005 Express edition. Any ideas what...
2
by: johnb41 | last post by:
I'm using .NET 2.0. My form is displaying the webbrowser control, which is displaying some HTML text. When printing with webbrowser.print(), my printout includes the header and footer. How...
0
by: Sin Jeong-hun | last post by:
I've found that if a MessageBox (called by alert/confirm from Javascript) or a web page modeless dialog is popped up, I cannot call Navigate of the WebBrowser control. If I do, a COM exception...
2
by: Zytan | last post by:
I have a WebBroswer control, and I set the HTML it will display via DocumentText, which takes a a string. This shows the HTML code from the string in the control. But, sometimes, the WebBrowser...
2
by: Scott Gravenhorst | last post by:
I recently (within 30 days) downloaded and installed VB 2005 Express. I like it a whole lot... but: I have been trying to work with the WebBrowser control to display a small amount of help text...
0
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
I am converting a windows application which contains a web browser control into an ASP.net application. The Windows project references all manner of html controls in the WebBrowser control and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.