Webfile create text file

hi
i am try to use this code but the record on the file after download is empty way

Var f As FolderItem

//Dim txtFile As WebFile
f = SpecialFolder.Temporary.Child(“MyTextFile.txt”) // Create in a temporary folder
Var s As String
Var listDta() As String

txtFile=New WebFile
txtFile.ForceDownload=True
txtFile.MimeType = “text/plain”
txtFile.Filename = f.Name

If f <> Nil Then
Var t As TextOutputStream = TextOutputStream.Create(f)

//// Write content to the file
try
t.write(“test1”)
t.write(“test2”)

t.Close

//// Set the WebFile properties

Catch e As IOException
MsgBox e.Message
end try
// Show the file for download
ShowURL(txtFile.URL)

End If

When you store a WebFile in a local variable like that, it goes out of scope and gets destroyed when the method finishes. In the event that the “download this” instruction gets to the user and the user’s browser takes action on it after the server side method has finished executing, the WebFile in question has been destroyed and the user can no longer download it.

To keep the WebFile around long enough for the user to download it, you’ll need to retain the reference in a property. Scope the property appropriately and keep it as tight as possible to when the WebFile is actually needed so that eventually it goes out of scope and gets destroyed. For lack of anywhere else to put it, an array property on Session will do the trick.

Edit: Also, up until //// Set the WebFile properties you haven’t done anything to put the file contents in the WebFile to send the end user. There is no code after that point which does so either in what you’ve posted. I don’t want to make any assumptions, but I’d start looking around here.

ok
thanks

now works i add
If f <> Nil And f.Exists Then
txtFile = WebFile.Open(f) //open the file as a webfile
txtFile.ForceDownload = True
End If

//ShowURL(txtFile.URL)
if txtFile <> Nil Then
ShowURL(txtFile.URL) //shows the savefile dialog to the user
end if
thanks

Unless you need the files later, you don’t have to actually write anything to disk. You can load the data directly into the WebFile.

ok
thanks