File Download


I would like offer download from a standalone xojo app (Microsoft). but I don’t know how to do this. The following source code I programmed, but it doesn’t work:

dim wf as new WebFile dim s as string ' s = "AIT_ATTACHMENTS/TEXTFILE.PDF" dim fd as FolderItem = GetFolderItem(s) if fd <> nil and fd.Exists then wf = WebFile.Open(fd) wf.ForceDownload = true if wf <> nil then ShowURL(wf.URL) end if else msgbox " not found " + s + " --- " + app.ExecutableFile.Parent.URLPath end if

The folder “AIT_ATTACHMENTS” is in the same folder as the standalone execution file.

Are there any more explanations or examples available for handling files?
I don’t know how to specify a path and filenames. I don’t know, what kind of tags I have to use. For example: “C:/AITTACHEMENT…”.

Can anybody give me a tip? Thank’s in advance?

Edit (Paul): Added Code tag.

I offer downloads to my customers with a program I started with an example that comes with Xojo :
Xojo 2014 Release 1/Example Projects/Web/Downloading/Downloading.xojo_binary_project

If the OS is Windows then your folder delimiter is backwards. Windows uses \ not /. To make this xplat you should do

s = "AIT_ATTACHMENTS" dim fd as FolderItem = GetFolderItem(s).child("TEXTFILE.PDF")

Thank you both. Now it works. That is the running source code:

dim s as string
Dim f As Folderitem = App.ExecutableFile.Parent.Child(s)

If f <> Nil And f.Exists Then
  Session.DownloadFile = WebFile.Open(f)
  Session.DownloadFile.ForceDownload = False
End If

If Session.DownloadFile <> Nil Then
  me.ExecuteJavaScript("'" + Session.DownloadFile.URL + "','Download');")
  MsgBox("The selected  file is not available.")
End If

I used a webfile property of the session (property name = DownloadFile) instead of a declared variable, how ever.

Because of the behaviour in Internet Explorer I didn’t used “ShowURL”, because the user have to use the “Back”-button. In that case the user have to login again. It’s not a good behaviour.
To avoid this, I used “… executeJavaScript(…”.