|
|
|
|
|
- Overview
- Implementing file download in a WEBDEV website
- Using the control description window (Button control, Link control, etc.)
- Programming
- Tip: to force file download (through programming only)
The download is the operation that consists in saving a file stored on the server onto the computer of Web user. The file is "downloaded" on the computer of Web user. For example: - A DVD site allows you to download movie trailers onto your computer.
- Documents can be downloaded into an application for document management.
Implementing file download in a WEBDEV website WEBDEV proposes several methods to perform a file download: - description window of the Button control or Link control used for the download.
- programming in WLanguage.
Using the control description window (Button control, Link control, etc.) To propose a download: - Create a "Link" control, "Button" control, ...
- Open the control description window.
- On the "General" tab, select "Custom link (email,phone, etc.)".
- In "Address", select "File".
- Specify the full path of file (directory + name) found on the server. The file must be in the "_WEB" directory of the site.
At runtime, when this Link or Button control is clicked on: - if the file type is recognized, the file will be directly opened in the browser
- if the file type is not recognized or if it corresponds to an executable, a dialog box allows you to download this file and/or to run it directly.
Programming To propose file download through programming, simply use FileDisplay in the server click code of the Button or Link used to download the file. The directory specified for the file must be a directory you can access and write to (for example, the data directory ( fDataDir) or resource directory ( fWebDir)). Example: // Displays the file in the browser // (if the format is recognized by the system, the file is displayed directly) FileDisplay(CompleteDir(fWebDir()) + "NOTES.TXT", "text/plain")
At runtime, when this Link or Button control is clicked on: - if the file type is recognized, the file will be directly opened in the browser.
- if the file type is not recognized or if it corresponds to an executable, a dialog box allows you to download this file and/or to run it directly.
Tip: to force file download (through programming only) To force the download regardless of the type of file, simply use the following line of code (in the server click code of the Button or Link control used to download the file): FileDisplay(CompleteDir(fWebDir()) + "NOTES.TXT", "application/unknown")
However, the name of file proposed for download does not correspond to a valid name. To immediately propose the name of the file to download, simply add this name after the parameters of FileDisplay. FileDisplay(CompleteDir(fWebDir()) + "NOTES.TXT", ... "application/unknown", "Notes.TXT")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|