Web App Simple Save Text to File?

Please could someone help me with a very simple solution to save the textfields in my Web App to a file?
I don’t mind if it’s a simple text file, but I’m assuming I can’t use text output stream etc in the way I did with local projects in RB.
Thanks in advance.

[quote=95859:@Adrian Bolton]Please could someone help me with a very simple solution to save the textfields in my Web App to a file?
I don’t mind if it’s a simple text file, but I’m assuming I can’t use text output stream etc in the way I did with local projects in RB.[/quote]

In a web app you always want to differentiate if the file should be saved on the server, in which case the text output stream is fine, or have it saved by the user on the browser side. In which case you save first on the server, and then you could use ShowURL to have the user download the file.

Thanks Michel. Forgive me for being so thick (I used to love RB and XOJO has totally thrown me).

In which case you save first on the server, and then you could use ShowURL to have the user download the file.

  • This is exactly what I want to do.

However, playing with the example text output stream code in my web app, I can’t get it to work and I don’t understand why:

  • I get errors on GetSaveFolderItem etc.

Dim file As FolderItem
Dim fileStream As TextOutputStream
file = GetSaveFolderItem("", “MyInfo.txt”)
If file <> Nil Then
fileStream = TextOutputStream.Create(file)
fileStream.WriteLine(NameField.Text)
fileStream.WriteLine(AddressField.Text)
fileStream.WriteLine(PhoneField.Text)
fileStream.Close
End If

What is the goal of this file?

Thanks Bob. It’s just to contain a record of prices from a quote calculator app. Basically the text from around 20 textfields. It doesn’t need to be formatted or anything. The app works, I just want the quickest way right now to save the results of the quote calculator in case there’s any customer queries in the future.

I now there are proper ways to do this, but as we are quoting daily right now, I just need the quickest option to implement easily. I can then revisit it later on.

You cannot use GetSaveFolder that way. Better save the file to the Temporary folder directly. I have turned the field names into strings for my test. The second part downloads the file. It has been takend from the web example “downloading” :

[code]Sub Action()
Dim fileStream As TextOutputStream
Dim f as folderitem = SpecialFolder.Temporary.child(“MyInfo.txt”)
If f <> Nil Then
fileStream = TextOutputStream.Create(f)
fileStream.WriteLine(“NameField.Text”)
fileStream.WriteLine(“AddressField.Text”)
fileStream.WriteLine(“PhoneField.Text”)
fileStream.Close
End If
msgbox "Prepare to download the file "+f.name

If f <> Nil And f.Exists Then
LogoFile = WebFile.Open(f)
LogoFile.ForceDownload = True
End If

if LogoFile <>Nil Then
msgbox LogoFile.url+endofline+f.urlpath
ShowURL(LogoFile.URL)
end if
End Sub
[/code]

Important : LogoFile is a WebPage WebFile property. Do not simply dim in the code, it would not last enough time to download.

That’s perfect Michel… Thanks so much! It’s all working as required. Very much appreciated!

You are welcome :slight_smile: