Downloads a file from the Web server to a client computer.
void DownloadFile (string serverFile, boolean open)
Argument |
Description |
---|---|
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: |
None
Some types of files cannot be displayed directly in a browser window. For these types of files, the open argument is disregarded. Instead, the File Download dialog box displays 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.
The following example opens the file aaa.txt in download mode:
#if defined PBWEBFORM then
DownloadFile("c:\aaa.txt", false)
#end if
The download mode causes the File Download dialog box to display, giving the user the choice of opening the file, saving the file, or cancelling the operation. The File Download dialog box displays the file name, the file type, the number of bytes in the file, and the name of the server that hosts the file.
The following code opens a dialog box that allows users to select a directory and download multiple files from the same directory:
string docpath, docname[]
boolean lb_openinteger i, li_cnt, li_rtn, li_filenum
lb_open = true //or false
li_rtn = GetFileOpenName("Select File", docpath, & + docname[], "DOC", & + "Text Files (*.TXT),*.TXT," & + "Doc Files (*.DOC),*.DOC," & + "All Files (*.*), *.*", & "C:\Program Files\Sybase", 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 then mle_1.text = string(docpath) #if defined PBWEBFORM then DownloadFile(string(docpath), lb_open) #end ifelse
// if multiple files are picked, docpath contains // the path only - concatenate docpath and docname
for i=1 to li_cnt
string s
s = string(docpath) + "\" +(string(docname[i]))
#if defined PBWEBFORM then
DownloadFile(s, lb_open)
#end if
mle_1.text += s +"~r~n"
next
end if