Mac path question

Hi all, I’ve got a question about paths in the App bundle, that I cannot get to the bottom of. I call up a local html page with the HTMLViewer in a window. I’ve got all this worked out on Windows (Release and Debug) and it works fine in Debug on the Mac.
f is a FolderItem that points to the file, and I display it with HTMLViewer.LoadURL(f.NativePath). Here is the path I use, works OK:

/Users/merv/Desktop/My_Source_Folder/MyApp.debug.app/Contents/Resources/Help/index.html

But in the Release build, this does not work when I start the app directly in the Finder Window that pops up after the build:

/Users/merv/Desktop/My_Source_Folder/Builds - MyApp.xojo_project/Mac OS X (Cocoa Intel)/MyApp.app/Contents/Resources/Help/index.html

However, if I drag the App to the Desktop first then start it up, it works fine. I guess technically everything is OK, but it is not clear to me why it won’t Show the HTML page when the app is started directly from “Builds - MyApp.xojo_project/Mac OS X (Cocoa Intel)”

Any ideas?

Do you see the differences in your paths? It’s the spaces.

HTMLViewers needs an escaped URL to load a file, so spaces must be turned into %20, and all of those other HTML entity lovelies. Luckily there’s a function in Xojo to fix this for us, it’s EncodeURLComponent

So you’re going to want something along the lines of:

dim helpHTML as FolderItem
helpHTML = TPSF.Resources.child("Help").child("index.html")

dim helpPathString as String = EncodeURLComponent(helpHTML.NativePath)

HTMLViewer.LoadURL(helpPathString)

[browser code disclaimer]

Thanks, Tim. That doesn’t seem to work, it replaces all the “/” characters with %2F and does not seem to be what it needs. But this works:

helpPathString = ReplaceAll(f.NativePath," “,”%20")

replacing only the spaces. It’s not clear to me from the HTMLViewer docs what exactly it is looking for, but the above does work. Thanks for the tip, got me pointed in the right direction. If there is something I am missing, let me know.

Try

helpHTML.URLPath

http://documentation.xojo.com/index.php/FolderItem.URLPath
That should escape the correct characters and leave the rest alone.

[quote=237528:@Merv Pate]Thanks, Tim. That doesn’t seem to work, it replaces all the “/” characters with %2F and does not seem to be what it needs. But this works:

helpPathString = ReplaceAll(f.NativePath," “,”%20")

replacing only the spaces. It’s not clear to me from the HTMLViewer docs what exactly it is looking for, but the above does work. Thanks for the tip, got me pointed in the right direction. If there is something I am missing, let me know.[/quote]
It’s not part of the HTML Viewer documentation, it’s a general web browser knowledge thing.
This document might help: http://www.w3schools.com/tags/ref_urlencode.asp

Using ReplaceAll on just spaces may not work - there are other characters that can break URLs, especially the pound sign. Hamish corrected my 1am knowledge with your best bet. I would swap your ReplaceAll with FolderItem.URLPath so you don’t have troubles down the road.

Would not URLPath be the simplest and right way ?

You can pass the folderitem directly and let Xojo sort that out for you. Check the docs.

Where do you see that?

I’m not at my computer, but check the old language reference. We use it in a number of apps.

This is what I am using:

HelpViewer.LoadURL(f.NativePath)

passing a folderitem, issues an error that it needs a string.

Michel and Hamish, that seems to be the best solution for a local file. HelpViewer.LoadURL(f.URLPath) seems to be what I am after.

http://documentation.xojo.com/index.php/HTMLViewer.LoadPage

OK, that works, thanks Norman. I think that is what I am looking for.

Here is what I have been using for several years. The first line is easier today with TPSF.

dim f as folderitem = app.executablefile.parent.parent.child("Resources").child("index.html") WebViewer.LoadURL(f.URLPath)