DownloadFile
Use to download a file from the Web server to a client computer.
Syntax
|
1 |
void <span>DownloadFile</span> (string <var>serverFile</var>, boolean <var>open</var>) |
Parameters
-
serverFile �
A string containing the name of the file on the application�s virtual file path on the Web server. -
open �
A boolean that determines whether to access the file in open mode or download mode. Values are:- true � show the file directly in a browser window (open mode).
- false � show a dialog box that lets the user open the file, save the file, or cancel the download operation (download mode).
Returns
None.
Examples
-
�
This example opens the file aaa.txt in download mode:
123#if defined PBWEBFORM thenDownloadFile("c:aaa.txt", false)#end ifThe download mode causes the File Download dialog box to appear, giving the user the choice of opening the file, saving the file, or cancelling the operation. The File Download dialog box shows the file name, the file type, the number of bytes in the file, and the name of the server that hosts the file.
-
�
This code opens a dialog box that allows users to select a directory and download multiple files from the same directory:1234567891011121314151617181920212223242526272829303132string docpath, docname[]boolean lb_openinteger i, li_cnt, li_rtn, li_filenumlb_open = true //or falseli_rtn = GetFileOpenName("Select File", docpath, &+ docname[], "DOC", &+ "Text Files (*.TXT),*.TXT," &+ "Doc Files (*.DOC),*.DOC," &+ "All Files (*.*), *.*", &"C:Program FilesSybase", 18)IF li_rtn < 1 THEN returnli_cnt = Upperbound(docname)// if only one file is picked, docpath contains the// path and file nameif li_cnt = 1 thenmle_1.text = string(docpath)#if defined PBWEBFORM thenDownloadFile(string(docpath), lb_open)#end ifelse// if multiple files are picked, docpath contains// the path only - concatenate docpath and docnamefor i=1 to li_cntstring ss = string(docpath) + "" +(string(docname[i]))#if defined PBWEBFORM thenDownloadFile(s, lb_open)#end ifmle_1.text += s +"~r~n"nextend if
Usage
Some types of files cannot be viewed directly in a browser window. For these types of files, the open argument is disregarded. Instead, the File Download dialog box appears, as if you set the open argument to false, but the dialog box provides no option to open the file directly. In this case, users can only save the file to disk or cancel the download operation.
If the file you indicate in the serverFile argument is not present on the server, application users do not see an error message. You can use the FileExists PowerScript function to make sure the file exists in the server directory before you call DownloadFile.