Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path problem in Internet Control

Status
Not open for further replies.

gabster

Programmer
Oct 23, 2001
192
0
0
US
Hi all,

I use Microsoft Internet Control to show a generated html im my VB app.
Basically am receiving an xml string from the server, and with a local xsl (stylesheet) I am outputting as HTML using the msxml3 parser.
However everything works perfectly fine but the images from my html page are mising. When I right-click and check the properties of an missing image, I get "about:sample.gif"... It looks like there is a path problem. However, the xml/xsl (html) works good as stand alone files so it is not an html error. That means if I save my xml string into an xml file, and openit with the browser, I can see everything fine.

This is the code I am using in my app:

Set xml = New DOMDocument
Set xsl = New DOMDocument

xml.async = False
xml.loadXML retMsg 'retMsg is the XML string I am getting from the server

xsl.async = False
xsl.Load (App.Path & "\tt.xsl") 'load stylesheet (xsl)


Final = xml.transformNode(xsl) 'mix them together and output as html - Final is a string variable

WebBrowser1.Navigate "about:blank"
WebBrowser1.Document.Open
WebBrowser1.Document.Write Final
WebBrowser1.Document.Close
WebBrowser1.Refresh


Thanks a lot,
Gabi.
 

The question that I have, is if you look at the source for the displayed page, what is the path for the images that are to be displayed??? My guess is that for some reason the path to where the images are located are not quite correct.

Those paths to the image are they http : // or are they file /// (spaces added so as not to create links)??
 
Very good point...

However:
1. with my VB app running I get this from the html source:
img src="./IMAGES/Sample.gif"

But if I right-click on a missing image and check it's url in the properties I get:

"about:blank./IMAGES/Sample.gif"

As if "about:blank" is messing things up.

2. I tried the xml/xsl page separately in the browser and there everything works fine. the image property path (URL) there looks like this:

"file:///C:/TEST/IMAGE/Sample.gif"

It looks to me that there must be a problem with my WebBrowser1.Navigate "about:blank" line...

I even removed that line and added a blank.htm instead of the "about:blank" part. Stil the path shows "about:blank./IMAGES/Sample.gif" as if that about:blank is misteriously cached somewhere.

Thanks,
Gabi.
 

I would then test your file with putting a full qualified path in, instead of a relative one and see if that works.
 
It works with that absolute path "file:///C:/TEST/IMAGE/Sample.gif"...

But I shouldn't consider that solved since everyone wil have a different location for my path...

Loks like I need some soret of a base href.

Thanks,
Gabi.
 

Ok, we have solved the mystery of will the images display at all. We know that they will with the absolute path, but that path may change as you have stated. So as you have suggested a base href may work or you may be able to change the relative paths at run time to fully qualified absolute paths based upon where the file was selected from.

The first test you should do is see if your relative path is incorrect. Play around with it a little bit.

The following is the resluts of my tests.

Path to htm file = C:\Z\Test.Htm

relative path in htm file = "\USA.JPG" did not work
relative path in htm file = "USA.JPG" did work
relative path in htm file = ".\USA.JPG" did work
relative path in htm file = "..\z\USA.JPG" did work
relative path in htm file = "C:\z\USA.JPG" did work

(Note: Image and test.htm were in same directory)

I Hope This helps, Good Luck
 
Thanks again

I tied all that. The only path that is working for me is the absolute "C:\z\USA.JPG"...

I think at least I localized my problem:

Since I have a XML string and XSL... And I do the transformation at runtime... and I do not have an initial html file to start with... and so on...
That's why it gets so tricky. I thing there would have been no problem with a residing html in my folder and pointing the path to it.

I even tried that by placing an empty.htm in my app's folder and navigating to that with WebBrowser1.Navigate (App.Path & "\empty.htm") in the form load.
No use...

I'll probably have to stick with the absolute path in my XSL and hope that the user will always use the same folder structure to install my application...

Thanks a lot for help...

GAbi.
 

Not necessarily! If the user is selecting the XSL file then you know its path. You could then parse out the XSL file and then add the full path to the images at run time. You could also use a hidden webbrowser to test for missing images with something like...

(To use this place a webbrowser control on a form and name it WB and place a command button on the form also)

[tt]
Option Explicit

Dim DoneDoc As Boolean

Private Sub Form_Load()
WB.Navigate "about:blank"
End Sub

Private Sub Command1_Click()

Dim FilePath As String, ImagePath As String, ImageUrl As String, BasePath As String
Dim C

DoneDoc = False
WB.Navigate "C:\Z\TEST.HTM"'nav to your file here
Do While DoneDoc = False
DoEvents
Loop

FilePath = WB.LocationURL'place break point here
FilePath = Mid(FilePath, Len("file:///") + 1)
FilePath = Replace(FilePath, "/", "\")
BasePath = Left(FilePath, InStrRev(FilePath, "\"))
For C = 0 To WB.Document.images.length
ImageUrl = WB.Document.images(C).href
ImagePath = Mid(ImageUrl, Len("file:///") + 1)
If Dir(ImagePath) = "" Then
ImagePath = "file:///" & BasePath & WB.Document.images(C).nameprop
DoEvents
End If
Next C


End Sub


Private Sub WB_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
If Progress = ProgressMax And ProgressMax > 0 Then DoneDoc = True
End Sub

[/tt]

just a little example on how you can tell if it is not right
 
The problem is with this line:

WB.Navigate "C:\Z\TEST.HTM"'nav to your file here

I do not have a phisical existing htm file. It is generated at run time (who knows where).
The only thing I have is the string variable "Final" that's the html string (the result of the XML/XSL transformation)...


If I can get rid of that annoying "about:blank" that comes from who-knows-where, the path would be cleared up (I guess).




 
I got it !!!!!

Just had to addd this in the header of my XSL file:

<base href=&quot;file:&quot;/>

Many thanks...

GAbi.
 

Ok you have a sting variable that you could then parse through and replace the relative paths with the full path.

That is if I understand you correctly.
 
exactly...

but i fix it with that <base href=&quot;file:&quot;/>...
It's the html version of App.Path.

Works perfectly fine now.

Thanks for help,
GAbi.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top