Delete file after download is complete

in Xojo Web standalone for Windows.
I am looking for an easy way to delete a temp file that is saved in the resources folder. The file is downloaded by the user and should then be deleted by the program after the download is complete. I have tried searching this forum and google but have not found a way to wait till the download is complete and then delete.
Here is the part of the code that does the download. Thanks in advance for any help.

Dim f As FolderItem = GetFolderItem("\\resources\" + me.cell(row, column)) If f <> Nil And f.Exists Then Session.MyFile = WebFile.Open(f) // "MyFile As WebFile" is a property on the Session Session.MyFile.ForceDownload = True ShowURL(Session.MyFile.URL) End If

I had a similar challenge. We are able to know that the request was sent to the browser to download the file, but we have no way to know that the download actually completed. I solved it by analysing the process flow. Once the user receives the file, he will then move on to the next process step. That is where I placed code to clean-up after myself.

Basically, it is not the code that decides when to delete the temp file, it is the user by taking the next action. Alternately, you could have the webfile and the folderitem as properties of the page or container instead of the session. When you close the page or container, you clean the folderitem up.

Louis
Thanks for the reply.
My problem is that the user may not have a next step. User may just close the browser window after the download is complete.
The list of files to download are in a WebListBox so the user may download 1 or more files. I guess that I could delete the last downloaded file if the ListBox Selectionchanged event is called and also delete the last download in the close or cancel close event. I am just trying to run some ideas thru my head. Do these ideas sound reasonable to you?
Thanks

I think that the idea is good. The user selects a new file, you can get rid of the previous one. It will leave the last file not removed.

Your use case includes the possibility that the user quits the application by closing the browser. That requires that you are able to track which of the temp files can be deleted. perhaps in an array of folderitems as properties of the session. Then clean everything up in the Session close event. Even when users close the browser, the session will eventualy close itself, so the event should fire. I never tried this, so tests are definitely in order.

Louis
I will give that a try and see how it works. I will post back later with the results.
Thanks