473,513 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18659
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
1754
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
2334
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
5064
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
2330
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
2628
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
1889
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
11121
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
6345
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
3242
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
7161
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
7384
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
7539
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
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
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,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.