473,799 Members | 3,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

webbrowser.Docu mentStream 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 12637
"Toma Marinov" <To*********@di scussions.micro soft.com> wrote in message
news:4C******** *************** ***********@mic rosoft.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 DocumentComplet ed 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
DocumentComplet ed 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...Bu t they are null, ""...
:o(( I'll continue to examine this situation...
Kind regards,
Toma

"Tim Anderson" wrote:
"Toma Marinov" <To*********@di scussions.micro soft.com> wrote in message
news:4C******** *************** ***********@mic rosoft.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 DocumentComplet ed 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*********@di scussions.micro soft.com> wrote in message
news:6C******** *************** ***********@mic rosoft.com...
Hello and thank you for your answer !
At the begining I thought that this was the problem, but when I process
DocumentComplet ed 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...Bu t 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 DocumentComplet e:

private void axWebBrowser1_D ocumentComplete (object sender,
AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event e)

{

mshtml.HTMLDocu ment htmldoc;

Microsoft.Offic e.Interop.Word. Document worddoc;

if (this.axWebBrow ser1.Document is Microsoft.Offic e.Interop.Word. Document) {

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

}

if (this.axWebBrow ser1.Document is mshtml.HTMLDocu ment)

{

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.AxWeb Browser, 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******** ******@TK2MSFTN GP11.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_Doc umentCompleted( ByVal sender As System.Object,
ByVal e As System.Windows. Forms.WebBrowse rDocumentComple tedEventArgs)
Handles WebBrowser1.Doc umentCompleted
Dim doc As Microsoft.Offic e.Interop.Word. Document

Dim docobj As Object

docobj = Me.WebBrowser1. ActiveXInstance .document

If TypeOf (docobj) Is Microsoft.Offic e.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
2823
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 .DocumentStream, but this property is null. The property .DocumentText is = "" too. Am I missing something ? Thank you very much !
2
7400
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 ( but this doesn't work ): WebBrowser.Navigate( "MyApplication.Sample.html" ) Does anyone know if
11
2846
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
1218
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 make it browse to a page. What I want to do is to get the HTML sourse inside a page. http://msdn2.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentstream.aspx shows a property as follows: Dim instance As WebBrowser Dim...
1
8405
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 there are anchor points in the document that I want to move to either on open or later; question is how do I do this with the above code?
0
3582
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 into a single MIME encoded file that specifies all of the resources for a page in a single file. This makes a lot of sense as if you could pass one of these to the
6
7549
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 isn't the current directory of the program. What is the current directory? I don't want to use an absolute path, since its contents are saved to disk, and that should always load the css file no matter where it and the css file exists. Titan
3
3175
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 files are created and stored in a temp folder. The older files from temp need to be deleted everytime prior to calling the Navigate function for the current file. But I am getting an exception when i try to delete the temp folder
0
4321
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 with a HttpWebRequest that goes to http://www.microsoft.com and this work fine, however if I change the URL to http://www.telerik.com or http://www.apple.com then the WebBrowser thows an unhandled Permission Denied error. I know that the...
0
10490
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
10259
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
10238
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
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7570
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
6809
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
5467
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...
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.