Saving TextArea content in a Web app

Hi, guys,

I am starting to work on conversion of one of my desktop apps into a web app.

Part of the functionality is saving a text in the TextArea as an file.

Is there a way to save TextArea content as a file in a web app? The file needs to saved to the user’s desktop.

Would MBS allow for saving as a PDF?

Thank you in advance,

Val

Do you need to retain formatting or just save the text itself to a text file?

Hi, Jonathan,

Probably, just the text is enough.

Thank you,

Val

Take a look at WebFile. There’s an example under the “Download” method that will do just that. Just change the line TextFile.Data = "Hello, world!", or you can utilize the first example on the WebFile page.

Hi, Jonathan,

Thank you for the advice. For some reason the app is returning an error 404: File Not Found.

I tried both just running from the project and running an app after deploying to the XOJO server - the same error 404.

Can you post the code you used?

I needed to change the first line of the code in the example because it was not compiling.

This is my code

Dim TextFile as New WebFile // "TextFile As WebFile" is a property of the web page
TextFile.MimeType = "text/plain"
TextFile.ForceDownload = True // If False, the browser may try to display the file instead of download it
TextFile.FileName = "TextFile.txt"

TextFile.Data = "Hello, world!"

ShowURL(TextFile.URL) // This causes the file to be downloaded

I will replace TextFile.Data with TextArea1.textt when I make the code from the example work.

Try setting “TextFile” as a property of your window or container control instead of instantiating it in code. I think the problem you’re having is the variable “TextFile” is going out of context and therefore doesn’t exist as soon as the method quits so the user’s browser is unable to find it.

You need to create a property with name TextFile type WebFile for your WebPage, then use the example as shown on the docs.

Hi, Jonathan and Alberto,

Thank you for your help. Now it works.

Thank you very much for all your help.

Val