PC SOFT

AYUDA EN LÍNEA
DE WINDEV, WEBDEV Y WINDEV MOBILE

Este contenido proviene de una traducción automática.. Haga clic aquí para ver la versión original en inglés.
  • Overview
  • Implementing file download in a WEBDEV site
  • Using the control description window (Button control, Link control, etc.)
  • Programming
  • Tip: forcing the file download (by programming only)
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Otros
Procedimientos almacenados
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 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 by programming, simply 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 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 (by 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")
Versión mínima requerida
  • Versión 9
Comentarios
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 01 2015