473,387 Members | 1,517 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,387 software developers and data experts.

webbrowser.DocumentStream question

Hello !
I made some test with webbrowser control in VS.2005. When I load a word
document in webbrowser through .Navigate method (from my hdd), I want to get
the stream of the loaded doc file with .DocumentStream, but this property is
null. The property .DocumentText is = "" too. Am I missing something ?
Thank you very much !

Jan 11 '06 #1
4 12603
"Toma Marinov" <To*********@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Hello !
I made some test with webbrowser control in VS.2005. When I load a word
document in webbrowser through .Navigate method (from my hdd), I want to
get
the stream of the loaded doc file with .DocumentStream, but this property
is
null. The property .DocumentText is = "" too. Am I missing something ?
Thank you very much !


The webbrowser loads documents asynchronously. This means that you cannot
access the document immediately after loading it. You have to wait for the
load to complete. You can handle the DocumentCompleted event or check the
ReadyState for a value of Complete.

Tim
Visual Studio 2005 DLL Hell:
http://www.itwriting.com/blog/?postid=261
Jan 12 '06 #2
Hello and thank you for your answer !
At the begining I thought that this was the problem, but when I process
DocumentCompleted event, I saw that the word document was loaded very fast.
After that on button.click event I try to acces DocumentStream or
DocumentText properties...But they are null, ""...
:o(( I'll continue to examine this situation...
Kind regards,
Toma

"Tim Anderson" wrote:
"Toma Marinov" <To*********@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Hello !
I made some test with webbrowser control in VS.2005. When I load a word
document in webbrowser through .Navigate method (from my hdd), I want to
get
the stream of the loaded doc file with .DocumentStream, but this property
is
null. The property .DocumentText is = "" too. Am I missing something ?
Thank you very much !


The webbrowser loads documents asynchronously. This means that you cannot
access the document immediately after loading it. You have to wait for the
load to complete. You can handle the DocumentCompleted event or check the
ReadyState for a value of Complete.

Tim
Visual Studio 2005 DLL Hell:
http://www.itwriting.com/blog/?postid=261

Jan 12 '06 #3

"Toma Marinov" <To*********@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Hello and thank you for your answer !
At the begining I thought that this was the problem, but when I process
DocumentCompleted event, I saw that the word document was loaded very
fast.
After that on button.click event I try to acces DocumentStream or
DocumentText properties...But they are null, ""...
:o((

I'll continue to examine this situation...


Apologies, I actually missed that it was a *word* document you were trying
to access.

If you look here:

http://msdn.microsoft.com/library/de...w/Overview.asp

you will see that the WebBrowser control is an ActiveX document container,
and that while it normally hosts MSHTML (to render HTML), it can also host
other types of document.

Note this remark:
"Because WebBrowser objects are ActiveX objects, the WebBrowser objects can
host objects other than HTML documents. Check for the type of document you
are hosting."

and this remark concerning the WebBrowser's Document property:

"When other document types are active, such as a Microsoft Word document,
this property returns the document automation object of that document. For
Word documents, this would be the Document object."

However, the WebBrowser wrapper in VS 2005 exposes a Document property that
is specifically an HtmlDocument. You can overcome this by importing the
ActiveX Microsoft WebBrowser control, in which the Document property is of
type object. Using the following code I successfully cast this to a Word
document in DocumentComplete:

private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)

{

mshtml.HTMLDocument htmldoc;

Microsoft.Office.Interop.Word.Document worddoc;

if (this.axWebBrowser1.Document is Microsoft.Office.Interop.Word.Document) {

MessageBox.Show("Got a word document");

}

if (this.axWebBrowser1.Document is mshtml.HTMLDocument)

{

MessageBox.Show("Got an HTML document");

}
}

.... So, how do you get at this property while using the new wrapper? My
first thought was to cast the ActiveXInstance property to an

AxSHDocVw.AxWebBrowser, but that doesn't appear to work. Ideas anyone?

Tim

Read my tech blog:

http://www.itwriting.com/blog


Jan 13 '06 #4

"Tim Anderson" <ti*****@nospam.hotmail.com> wrote in message
news:O3**************@TK2MSFTNGP11.phx.gbl...
... So, how do you get at this property while using the new wrapper? My


VB can do it. This works:

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs)
Handles WebBrowser1.DocumentCompleted
Dim doc As Microsoft.Office.Interop.Word.Document

Dim docobj As Object

docobj = Me.WebBrowser1.ActiveXInstance.document

If TypeOf (docobj) Is Microsoft.Office.Interop.Word.Document Then

doc = docobj

MessageBox.Show("Got a word doc")

End If

End Sub

So what is the equivalent C# code?

Read my tech blog:

http://www.itwriting.com/blog
Jan 13 '06 #5

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

Similar topics

1
by: Toma Marinov | last post by:
Hello ! I made some test with webbrowser control in VS.2005. When I load a word document in webbrowser through .Navigate method (from my hdd), I want to get the stream of the loaded doc file with...
2
by: FishingScout | last post by:
I have a small html file that I have added to my project. When I added "sample.html", I set the build action to "embedded resource". In the application I would like to do something like this (...
11
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
0
by: Anil Gupte | last post by:
I once (long time ago in VB 6) used the WebBrowser Control. I looked it up on MSDN and it showed how to add it into the Toolbox. So that worked fine. However, I cannot do much with it other than...
1
by: Andy Bates | last post by:
Hi - I have a form hosting the above control. I can generate the HTML as a Stream and set it in the control using: this.webBrowser1.DocumentStream = myStreamOfHTML. The problem is that...
0
by: Andy Bates | last post by:
Hi - This issue seems to have been kicking around since the dawn of time and no one appears to have come up with an answer. In short the MHT/MSHTML provides a method of archiving an HTML page...
6
by: titan.nyquist | last post by:
The WebBrowser control won't load a css file written in the same directory as the program. If I put an absolute path to it, it will load it. Thus, the current directory of the WebBrowser control...
3
by: =?Utf-8?B?R2F1cmF2?= | last post by:
I am using the AxSHDocVw.AxWebBrowser control (named PreviewBrowser) in my C# app to load a pdf file: PreviewBrowser.Navigate(strPDF ,ref objNull,ref objNull,ref objNull,ref objNull); These PDF...
0
by: =?Utf-8?B?VGFyZXE=?= | last post by:
Hi I was wondering if it is possible to to set the DocumentStream of the WebBrowser control to the stream that is returned from a HttpWebResponse.GetResponseStream()? I have actually tried this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.