Use to download a file from the Web server to a client computer.
void DownloadFile (string serverFile, boolean open)
None.
#if defined PBWEBFORM then DownloadFile("c:\aaa.txt", false) #end if
The 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.
string docpath, docname[] boolean lb_open integer 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 return li_cnt = Upperbound(docname) // if only one file is picked, docpath contains the // path and file name if li_cnt = 1 then mle_1.text = string(docpath) #if defined PBWEBFORM then DownloadFile(string(docpath), lb_open) #end if else // 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
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.