ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Web-specific functions / Miscellaneous WEBDEV functions
  • Overview
  • Implementing file download in a WEBDEV site
  • Using the control description window (Button control, Link control, etc.)
  • Programming
  • Tip: forcing the file download (through programming only)
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
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 site
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:
  1. Create a "Link" control, "Button" control, ...
  2. Open the control description window.
  3. In the "General" tab, select "Custom link (email,phone, etc.)".
  4. In "Address", select "File".
  5. 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: forcing the 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")
Minimum version required
  • Version 9
Comments
Example Download Files via Mobile, Webdev, Windev (Download de arquivos)
//HTM_Download..URL="http://www.7-zip.org/a/7z920.exe"

OK is boolean = HTTPRequest("http://www.7-zip.org/a/7z920.exe")

IF OK = True THEN

Arquivo is Buffer = HTTPGetResult(httpResult)

IF InSimulatorMode() = True
OK = fSaveBuffer("c:\download\7z920.exe",Arquivo)
ELSE
OK = fSaveBuffer("/mnt/sdcard/7z920.exe",Arquivo)
END

IF OK = True THEN

IF InSimulatorMode() = True
OK = fFileExist("c:\download\7z920.exe")
ELSE
OK = fFileExist("/mnt/sdcard/7z920.exe")
END

IF OK = True THEN
Info("Download do arquivo 7z920.exe com sucesso!")
ELSE
Error("Nao foi possivel encontrar o arquivo do 7z920.exe. "+ErrorInfo(errMessage))
END

ELSE
Error("Nao foi possivel efetuar o download do 7z920.exe. "+ErrorInfo(errMessage))
END

ELSE

Error("URL nao encontrado para download do 7z920.exe. "+ErrorInfo(errMessage))

END
adrianoboller
17 Jan. 2015

Last update: 05/26/2022

Send a report | Local help