Saving a text field as a text file in a web application

Hi, is it possible to save the content of a text field in the form of a text file in a web application?

I made it work in a desktop application using SaveAsDialog, and have no idea how to approach the issue in a web application. Tried WebDialog but still confused.

Thank you.

Val

If you’ve considered the need for a SaveAsDialog you’ve officially passed the point of usefulness for a web app and you should be making a desktop app.

[quote=121438:@Valeriy Kozmenko]Hi, is it possible to save the content of a text field in the form of a text file in a web application?

I made it work in a desktop application using SaveAsDialog, and have no idea how to approach the issue in a web application. Tried WebDialog but still confused.
[/quote]

Do you really need input from the user to know the name of the file ? If not you can go

f = specialfolder.ApplicationData.child("myfile.txt")

And it will save myfile.txt into /home/UserName/

You can also use WebDialog to have the user enter a name in lieu of myfile.txt.

You can save in any folder you want that is accessible to your app with

f = GetFolderItem("/folder/folder/")

“folder” being whatever you want in a path.

[quote=121438:@Valeriy Kozmenko]Hi, is it possible to save the content of a text field in the form of a text file in a web application?

I made it work in a desktop application using SaveAsDialog, and have no idea how to approach the issue in a web application. Tried WebDialog but still confused.

Thank you.

Val[/quote]
Do you need to save on the server or the client side?

That’s right. I gave him indications only for server side, and did not mention downloading a WebFile. Sorry.

Hi, guys,

Thank you for your help.

I need the file to be saved on the client side.

Thank you again.

Val

Look for WebFile. This page has an example of what you want to do :
http://documentation.xojo.com/index.php/WebFile

Thank you, Michel,

I’ve started examining the code on the page you gave me.

I appreciate your help.

Val

HI, guys,

I have tried the code


TextFile = New WebFile // TextFile 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

When I run the application, the web browser returns the following error

The requested URL “/113686C1DC4B9128E65FA70A89AD0AFC/files/%7B0886-7615-7886-1939-8901%7D/TextFile.txt” could not be found. Please check your request and try again.

Not sure what is wrong.

I am using Xojo 2013r2 Mac version.

Thank you in advance.

Val

[quote=121669:@Valeriy Kozmenko]I have tried the code

When I run the application, the web browser returns the following error

The requested URL “/113686C1DC4B9128E65FA70A89AD0AFC/files/%7B0886-7615-7886-1939-8901%7D/TextFile.txt” could not be found. Please check your request and try again.[/quote]

From what I can see, you have copied exactly the example from the LR. I did the same in 2014R2.1 on Mac, and it triggers the download fine.

Hi, Michel,

I found my mistake. Now it works as it should be.

Val