473,661 Members | 2,501 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 18690
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
1767
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
2339
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
5070
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
2343
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
2632
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
1902
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
11131
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
6350
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
3253
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
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
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
8758
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
6185
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
5653
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
4179
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...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1743
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.