PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Implementing file download in a WEBDEV site
  • Using the description window of controls (button, link,...)
  • Programming
  • Tip: forcing the file download (by programming only)
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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.
Some examples:
  • 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 button or link used to perform the download.
  • programming in WLanguage.

Using the description window of controls (button, link,...)

To propose a download:
  1. Create a "Link" control, "Button" control, ...
  2. Display the description window of the control.
  3. Click the "Other actions" button.
  4. In the window that is displayed, select "Other actions: enter a link".
  5. Specify the full path of file (directory + name) found on the server. The file must be found in the "_WEB" directory of site.
At run time, when a click is performed on this link or button:
  • 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 by programming, use FileDisplay in the server click code of the button or link used to download the file.
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 run time, when a click is performed on this link or button:
  • 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 (by programming only)

To open this dialog box regardless of the type of file to download, use the following code line (in the server click code of the button or link 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 file to download, add this name after the parameters of FileDisplay.
FileDisplay(CompleteDir(fWebDir()) + "NOTES.TXT", ...
"application/unknown", "Notes.TXT")
Related Examples:
WWDLoad Complete examples (WEBDEV): WWDLoad
[ + ] Site for downloading software. The site is used to upload software, to organize them by family, to associate them with keywords. The software are presented as clouds of tags. You have the ability to perform searches in the site.
Minimum required version
  • 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
Jan. 17 2015