From Xojo Documentation

Revision as of 20:39, 13 November 2020 by Gperlman (talk | contribs) (Example)

Class (inherits from Object)

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.


Cached fa-lock-32.png ForceDownload URL fa-lock-32.png
Data MIMEType UseCompression
FileName Session

Download Identifier

Shared Methods

Constructor(forSession As Boolean = true)


To get a reference to an existing FolderItem, use the Open shared method.

If you find that FireFox users can't download files, try using WebSession.GotoURL and pass True for the InNewWindow parameter as well as having the user disable popup blockers.


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 = 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!"

TextFile.Download // 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:

Var f As FolderItem = New FolderItem("MyFile.txt")
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:

If App.MyFile <> Nil Then
GotoURL(App.MyFile.URL) // Download the file
End If

See Also

HTMLViewer, WebImageView, WebPicture, FolderItem, ShowURL