SaveFile
(System Library)
Description: | Helper function to save files or streams on a server, VIC or Anywhere Client |
Returns: | Object reference to itself. |
Usage: | Script Only. |
Function Groups: | File I/O, |
Related to: | BlockWrite | BuffStream | ClientSocket | CloseStream | FileStream | GetStreamLength | PipeStream | SRead | StreamEnd | SWrite |
Format: | System.SaveFile(Input, Destination, MimeType[, DeleteOnCompletion, pResultPath, pCompletionVar, OpenFileDialog, FilterPattern, FilterDesc, FileExt]) |
Parameters: |
Input |
Required. Input stream, file name or full path to file name to be saved. Alternatively, may be a callback module that will write data. The callback module should be a launched module and may have two parameters. The first is required and must be a stream to which data will be written. The second is optional and typically called pAbortSave, which is a pointer to a value that the callback can set to TRUE if the SaveFile operation is to be aborted. If that flag is set, anything that has already been written to the file will be discarded. If the destination already existed, it's original contents will have already been deleted so pAbortSave cannot be used to stop that from happening). |
Destination |
File name or path to save to. |
MimeType |
Mime type to send to the Anywhere Client in "view" mode. |
DeleteOnCompletion |
Optional Boolean. Defaults to False. Delete input on completion. Applies only when using a file name as the Input parameter. Does not apply to a stream. |
pResultPath |
Optional pointer to output destination. The output destination can be a string of the resulting file name including its path if the user selected a file, or can be Invalid if the user canceled the selection or the session is running on the Anywhere Client. |
pCompletionVar |
Optional pointer to percentage completion of writing the stream to the VIC. Invalid for the Anywhere Client or server sessions. |
OpenFileDialog |
Optional Boolean. TRUE to open FileDialogBox. Defaults to TRUE. |
FilterPattern |
Optional. Array of wildcard file patterns for the file types that will be offered to the user. |
FilterDesc |
Optional. Array of text values that are the descriptions corresponding to the FilePattern values. |
FileExt |
Optional text expression giving the default file extension to use if the user does not specify one. |
Comments: |
When run on a workstation or VIC a "save as" dialogue will be displayed. After being accepted, the input file or stream will be copied to that destination. On the Anywhere Client a file download will be initiated.
If DeleteOnCompletion is true and the input is a file, it will be deleted when it is no longer required by System.SaveFile(). You are strongly advised to use this rather than other means to delete the input file after transfer. Otherwise, the file may be deleted before the transfer is complete. |
Example:
This will save "output.csv" to the location of a user's choosing, or when run on the Anywhere Client it will initiate a download of "output.csv".
If WinButton(20, 150, 140, 170, 0, "Make CSV", 1); [ Stream = BuffStream(Concat("name,value", System.CRLF, "example1, 111", System.CRLF, "example2,222", System.CRLF, "example3,333", System.CRLF)); System.SaveFile(Stream, "output.csv", "text/csv"); ]