Web ShowURL does not open downloaded file

Hello All,

The following snippet of codes is from the Action event of a web button “Open File” on a modal dialog (to deal with downloading, viewing and uploading of attachments).
The intention of the web button action is to download a database blob into a file on the client computer, and to open it with the default program associated with the file on the same client computer.

In this example, I hard-coded the folder and file names.

TargetFolder = “c:\users\shusin”
tStr = “a test file.xlsm”
FileName = TargetFolder + tStr
fTarget = new FolderItem(FileName, FolderItem.PathTypeShell)

dim bs as BinaryStream = BinaryStream.Create(fTarget, true)
If bs <> nil then
bs.write(blob)
bs.close

  Dim ff As new Folderitem(FileName, FolderItem.PathTypeShell)
  If ff <> nil and ff.Exists Then
    Dim DownloadFile As WebFile
    DownloadFile = new WebFile
    DownloadFile = WebFile.Open(ff)
    DownloadFile.ForceDownload = True
    Call DownloadFile.Download
    MsgBox(fTarget.URLPath)  //#1
    Me.ShowURL(fTarget.URLPath, True)  //#2
  End If

End If

When executed, #1 (from Msgbox above) shows: file:///c:/Users/shusin/a%20test%20file.xlsm, as expected.

Also, by the time this message popped up, I could see the file had been downloaded successfully in the target folder, and I could open it (in Excel) when I double-clicked on it in Windows explorer.

However, #2 (from ShowURL) was not successful. Firstly, it did not launch in a new window (as specified w/ True in the second parameter), and secondly, it failed with HTTP 404 Not Found.
The URL of this launched page was: http://127.0.0.1:2222/9E776B75A04049BF39DB6FF0D6D96DD3510CB6FD/files/2947-3757-0851-1744-1518/a%20test%20file.xlsm

What do I do wrong here? Any guidance and suggestions are welcome. FYI, I am still using version 2018 release 2, for company policy reasons.

-Simon

You must call the file with the http url. You can use WebFile for that (and perhaps set forcedownload)

Atleast i think that you might want a remote user to view the file right?

The problem is that the web file variable is going out of scope at the end of the method and then isn’t available when the browser requests it.

Thanks for the responses, Derk, Greg.

As soon as I saw you mentioning “going out of scope at the end of the method”, I remember having the same issue 3+ years ago. :frowning:
It’s working now by using a session property As WebFile, see the use of Session.propDownloadFile in the snippet of codes below.


fTarget = new FolderItem(FileName, FolderItem.PathTypeShell)

dim bs as BinaryStream = BinaryStream.Create(fTarget, true)
If bs <> nil then
bs.write(blob)
bs.close

  Dim ff As new Folderitem(FileName, FolderItem.PathTypeShell)
  If ff <> nil and ff.Exists Then
    Session.propDownloadFile = new WebFile
    Session.propDownloadFile = WebFile.Open(ff)
    Session.propDownloadFile.ForceDownload = True
    Call Session.propDownloadFile.Download
    'MsgBox(fTarget.URLPath)
    ShowURL(Session.propDownloadFile.URL, True)

End If

Thank you very much for the explanation, Greg!

-Simon