WebFile
From Xojo Documentation
Supported Platforms Project Types: Web Platforms: macOS, Windows, Linux |
WebFile is used to create binary content for the user to download. As long as the WebFile is in memory (something has a reference to it) the file will be available. Once the object is disposed of, the file will no longer be available for download. Make sure you keep a reference in a WebPage, the session or on a control to make sure the WebFile lives long enough for the download to finish.
Events | |
|
Properties | |||||||||
|
Methods | |
|
Shared Methods | |
|
Notes
To get a reference to an existing FolderItem, use the Open shared method.
Example
This example creates a text file to make available for download. You can put it on the Action event handler for a WebButton so that the file is downloaded when the user clicks the button:
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
If you instead want to download an existing file on the server, you need to create a WebFile that points to it and save the reference. The best way to do this is to use a property of the WebApplication class. In the App.Open event handler:
If f <> Nil And f.Exists Then
App.MyFile = WebFile.Open(f) // "MyFile As WebFile" is a property on the App object
App.MyFile.ForceDownload = True
End If
Now in a WebButton on a page, you can download this file like this: