How to know when user has downloaded WebFile

In my Web app, I create WebFiles for users to download. I have to keep the reference alive until they finish the download, even though they might move to a different page in the app or start downloading additional files in it.

If I append a Web File to a WebFiles() array property in session or app, that seems to work well to let them download regardless of whatever else they do, but it leaves me with two issues:

  1. MY URGENT QUESTION: How do I know when their download is complete so that I can remove the WebFile from the array to free up memory?
  2. A minor thing I haven’t tested: I assume that if the array is in Session, a large download will break if they leave the Web app but their browser is still open. Does this mean I pretty much have to put the array as an App property to have it work and session isn’t really a good option?

The way I approach it is to handle downloads in specific webcontainers. The webfile is a property of the webcontainer. When the user leaves the container - presumably he has the file, the corresponding folderitem is deleted. Where I create multiple files, I keep an array of folderitem references and clean up all of them upon exit. (container, page, it depends on the specific case.) The key is I always do it on a basis of specific containers rather than the session. It is easier to know when to dispose of the files.

The way I handle this is on each WebSession I have a property that is an array of webfiles.
I then create a DownloadFile method on the Session
The download complete delegate removes it from the sessions array of webfiles

Protected Property Downloads() as WebFile

Public Sub DownloadFile(file as WebFile, inNewWindow as Boolean = false) Downloads.Append(file) AddHandler file.Downloaded, WeakAddressOf FileDownloaded showurl(file.url, inNewWindow) End Sub

Public Sub FileDownloaded(file as WebFile) downloads.Remove(Downloads.IndexOf(file)) RemoveHandler file.Downloaded, WeakAddressOf FileDownloaded file = nil Exception break End Sub

[quote=391180:@Brock Nash]The way I handle this is on each WebSession I have a property that is an array of webfiles.
I then create a DownloadFile method on the Session
The download complete delegate removes it from the sessions array of webfiles
[/quote]
I’m also dealing with this problem. I thought I’d do like this, but the Downloaded event is called once the file starts to download, not when it has finished. So, for a large file (or on a low Internet connection), only a few bytes would be sent and the download gets canceled. What’s the proper way of dealing with that?
A related question: if the user leaves the page (and the app altogether), browsing another website, would the download abort since the WebFile object goes out of scope? How will that appear to the user?

[quote=466221:@Arnaud Nicolet]I’m also dealing with this problem. I thought I’d do like this, but the Downloaded event is called once the file starts to download, not when it has finished. So, for a large file (or on a low Internet connection), only a few bytes would be sent and the download gets canceled. What’s the proper way of dealing with that?
A related question: if the user leaves the page (and the app altogether), browsing another website, would the download abort since the WebFile object goes out of scope? How will that appear to the user?[/quote]

Are you sure you implemented it correctly? I have not experienced any of these issues. Did you ensure the FileDownloaded method is on the Session object?

Well, even the Language Reference mentions the Downloaded event is executed when the browser initially requests the file. My code is really simple:
dim f As FolderItem
dim i As Integer
dim w As WebFile

i=LBFiles.ListIndex
if i>-1 then
f=LBFiles.RowTag(i)
if f<>nil then
w=WebFile.Open(f,False)
w.ForceDownload=True
if w.Download then WFToDownload.Append w
End If
end if

WFToDownload is a WebFile array. It doesn’t belong to the session, but it’s in the main window (which doesn’t go out of scope while the download runs).

Thanks.