Toma Marinov said:
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, ""...
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/default.asp?url=/workshop/browser/overview/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