Downloading a CVS generated in a WebApp

Trying to download a CSV file that contains the information of a WebListBox
Once the CSV was generated and placed it in a string (CSVstring), I am using the following code:

dim TextFile as New WebFile
TextFile.MimeType = “text/plain”
TextFile.ForceDownload = True
TextFile.FileName = “myfile.csv”
TextFile.Data = CSVstring

in order to download the CSV file.

The message I received from the browser is:
404: File Not Found
The requested URL “/494E0508F1017CC2D38B0DA8EDBCFA43849896AA/files/8725-5288-0594-4434-1326/myfile.txt” could not be found. Please check your request and try again.

Someone could give me a hand telling me what I am doing wrong ?

The WebFile is going out of scope before the browser can download it. Store the WebFile as a property that will stay in scope long enough.

Great Tim… Thanks a lot.