Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have a webbrowser I am trying to use to display a Manual.htm that is built using MS Word. This manual is for an aplication I have written. I have tried all the MS word save functions that save the file as a Html or web page document. This is the wierd part the document will show correctly if it is opened from Internet Explorer(I even saved this webpage that was displayed correctly in IE and tried using this file in the webbrowser control but it still did not show the pictures).
But from my application it will show all the text with it's formating but a blank area is shown where the picture is. There is no red X or any thing that would represent the picture having a problem.
I have tryed all the suggestions I found in searches for this type problem. My system is completely up to date with all MS updates. I am running windows 7 ultimate, Visual Studio ultimate, VB, on a 32 bit laptop. The code below is what I last tried in the code using the webbrowser control.
VB
sitepath = System.IO.Path.Combine("C:\Users\Curtis\Documents\Manual.html")
       Dim theStreamreader As New StreamReader(sitepath)
       Dim file As String = theStreamreader.ReadToEnd()
       'RichTextBox1.Text = file
       WebBrowser1.AllowNavigation = True

       WebBrowser1.DocumentText = file
       theStreamreader.Close()

The only thing I can think of is some setting either in the webbrowser or Visual studio that is causing this but I cannot find that setting. I have not tried publishing the application yet to see if it still done this after publishing but in debug it should work as in a published version.

Thanks for any help in this.

Curtis
Posted
Updated 14-Aug-11 8:10am
v2

Be sure that your images are in the same folder as your HTML documents, and you can then use relative paths with the WebBrowser control. Don't use the Document.Text property for navigation. Use the WebBrowser.Navigate() method. This way the WebBrowser "knows" that the document and the images are in the same folder. Setting the Document.Text property does not tell the WebBrowser where your files are located.

From my experience with earlier versions of Word, it creates terrible HTML. You'd likely be better off to write your own HTML if you're comfortable with it, or visit download.com[^] and find a different WYSIWYG editor.
 
Share this answer
 
Comments
Curtis Underwood 15-Aug-11 17:18pm    
Now that I actually edited the HTML file and set a full path in the src for the pictures I can understand why the relative path is not working.
I had used the navigate method earlier and it did not work, but I believe that is because of the way MS word makes the relative src path but I am not sure of this(Ms put the pictures in a subfolder of the main save folder, this subfolder name is the "filename_files/picture.png". This I believe is the reason the relative path fails.
Becuase of the number of pictures that this manual contains and the difficulty when publishing in having to bring this many files with the published version install. I think my best bet is to just supply a MS word document as the manual they can print or view instead of making it a part of my application. I even considered usin a pdf file an this worked, but the side content list did not show as I expected so I aggree with you that MS word is not that great as far as making PDF or HMTL's.

Thanks
Curtis
Alan Burkhart 15-Aug-11 19:34pm    
Some vendors create .doc or .rtf files for documentation. If you go that route, I'd recommend .rtf simply because Windows comes out of the box with Wordpad, which is a .txt/.rtf editor. Not everyone will have Word or OOo. In an app I released last year I used a WebBrowser control in the right panel of a SplitContainer control, and a column of LinkLabel controls in a single-column TableLayoutPanel in the left panel. Each label's Click event was set to an HTML doc and opened it in the WebBrowser. The HTML docs and images were all stored in the app's resources and were written to a Help directory the first time the app was launched. It worked well. Anyway, just an idea. Best of luck.
0) Why are you calling Path.Combine when you're not combining anything?

1) The WebBrowser control requires that image file names be fully qualified. In other words, you can't use "filename.jpg" - you must instead us "C:\myfolder\filename.jpg".

It's a major pain in the ass.
 
Share this answer
 
Comments
Curtis Underwood 14-Aug-11 18:28pm    
John,
Your answer about the fully qualified path is correct I went back and used word pad to edit the src= path that tells where the file is and it works correctly.

Thanks
Curtis
It can't save the pictures "in" a html file; they're probably in a subfolder with the same name. Try saving it as a "mht" file, that should embed the pictures within a single file that the browser can display.
 
Share this answer
 
Hi,
Eddie I did make mht file using MS word save files as mht and it did the same thing.

John the path combine I had tried with combining another path and just left it in because I was not sure I would need it further. But it did not affect the path that is being used so I left it.
As to the fully qualified names I did not know this and this file is built by word so how would I place this in the file? Would I have to edit each call made to the image file such as src=C:\Users\Curtis\Documents\Form1.png
or use some other method?

Curtis
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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