473,589 Members | 2,652 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.Nav igate(http://www.google.com);

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

and after that try this:

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

string html;

html = webBrowser1.Doc umentText.ToStr ing();

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

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 18682
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
DocumentComplet ed event and then getting the text from the document from
there.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"- 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.Nav igate(http://www.google.com);

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

and after that try this:

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

string html;

html = webBrowser1.Doc umentText.ToStr ing();

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

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_Doc umentCompleted( object sender,
WebBrowserDocum entCompletedEve ntArgs e)
{

string html;

MessageBox.Show ("Document Completed");
html = webBrowser1.Doc umentText.ToStr ing();
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.co m

"- 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_Doc umentCompleted( object sender,
WebBrowserDocum entCompletedEve ntArgs e)
{

string html;

MessageBox.Show ("Document Completed");
html = webBrowser1.Doc umentText.ToStr ing();
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.Nav igate(...);

?
Jun 5 '07 #5
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:%2******** ********@TK2MSF TNGP04.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.Nav igate(...), and watch DocumentText in
debugger after DocumentComplet ed event this is what I get:

<DOCUMENT_TEX T>
- DocumentText '((System.Windo ws.Forms.WebBro wser)(sender)). DocumentText'
threw an exception of type 'System.IO.File NotFoundExcepti on' string
{System.IO.File NotFoundExcepti on}
- base {"The system cannot find the file specified. (Exception from HRESULT:
0x80070002)":nu ll} System.IO.IOExc eption {System.IO.File NotFoundExcepti on}
- 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 DocumentComplet ed 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.co m

"- Electronic.HR -" <el***********@ gmail.comwrote in message
news:f4******** **@news1.carnet .hr...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote
in message news:%2******** ********@TK2MSF TNGP04.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.Nav igate(...), and watch DocumentText in
debugger after DocumentComplet ed event this is what I get:

<DOCUMENT_TEX T>
- DocumentText '((System.Windo ws.Forms.WebBro wser)(sender)). DocumentText'
threw an exception of type 'System.IO.File NotFoundExcepti on' string
{System.IO.File NotFoundExcepti on}
- base {"The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)":nu ll} System.IO.IOExc eption
{System.IO.File NotFoundExcepti on}
- 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 DocumentComplet ed 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
1765
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 disk. If I try to save the contents of the WebBrowser.DocumentText to disk, the resulting file contains HTML and script that I don't want. Is there any way I can save the actual XML document to disk from the WebBrowser control?
2
2337
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 disk. If I try to save the contents of the WebBrowser.DocumentText to disk, the resulting file contains HTML and script that I don't want. Is there any way I can save the actual XML document to disk from the WebBrowser control?
2
5069
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 file. So there are only part of the html file is showed in the RichtextBox. Anyone has idea about this problem? Thanks. Lewis
1
2338
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 might be causing this and how to get the entire page displayed in the browser? Thanks.
2
2631
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 can I remove the header and footer from the print out? Can this be done? If i can suppress the header and footer, i think this might be a really
0
1900
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 occures. How can I disable javascript MessageBoxes or modeless dialogs? I disabled normal popup windows by adding e.Cancel=true at the browsers newwindow event. But I couldn't disable modeless dialog or javascript MessageBox. I tried to remove some...
2
11126
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 shows nothing. Clicking 'view source' shows: "<HTML></HTML>", and the filename is called "about_blank.txt", which is the about:blank URL. I am aware that when you set this property, the WebBrowser control automatically navigates to the...
2
6347
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 for my application and though I've finally made it work, it seems a bit quirky, so perhaps that's the control being quirky or perhaps there is something I don't understand. 1) I could not figure out a way to make the webbrowser object display a...
0
3248
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 retrieves values using the HtmlControlCollection class etc. I was hoping I was going to be able to work with the Windows.Forms.WebBrowser object from inside my ASP.net webform by simply adding a reference to System.Windows.Forms and doing code...
0
7931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8233
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8360
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6637
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5731
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3849
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1461
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.