Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to read each WebBrowserstream and then i wanna copy it to the richtextbox....i don't know how can i do this....please suggest me.....Thanks in advance
Posted
Comments
Alan Burkhart 29-Aug-11 14:27pm    
Are you wanting to capture the stream while it's being read, or after the document is loaded in the browser?
Do you want the content as displayed, or do you want the HTML code?
Does browser display from a local source or from a source on the web?
The devil is always in the details. :-)

1 solution

You cannot just "copy" it. If you do, it won't work as format required by RichTextBox is RTF (http://en.wikipedia.org/wiki/Rich_Text_Format[^]). Those formats are completely different; and there are no exact one-to-one correspondence between notions of these two different mark-up languages. So, you only can interpret one format as another one using some mapping and mapping rules you have to define.

In practice, however, you will probably deal with some HTML subset. Also, you can figure out reasonable rules in a pretty simple way: write some HTML code, copy it in browser and paste in RichTextBox (you can also use Wordpad.EXE); then compare the raw RTF results (use regular text viewer, not RTF-capable) with HTML source. Also use some RTF reference. After such research, you will have a pretty good idea of the mapping you want to have.

For RTF references, see:
http://msdn.microsoft.com/en-us/library/aa140284%28v=office.10%29.aspx[^],
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7105[^],
http://www.biblioscape.com/rtf15_spec.htm[^].

Now, you need to generate RTF using System.Windows.Forms.WebBrowser control with some HTML page loaded from some URL. I don't think you need to use WebBrowser.DocumentStream property, because… this is only a stream. You can use it, but now, when I hopefully ruined you hope for just copying a stream in a stream (sorry about that :-)), you should understand that you would need to parse its content anyway. Why? You would need to use some third-party HTML parser; they are available but… those are all hassles.

Instead, you can immediately use the instance of the DOM model
for a currently load document using the property WebBrowser.Document. You can traverse all the element starting from this DOM Node and directly map all the children onto your RTF code

That will really do the trick.

Good luck,
—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900