Page 1 of 1

Warn for file overwrite when using showFileSaveDialog

PostPosted: Wed Oct 05, 2011 6:06 pm
by rossent
Hi all,

We need to provide option to users to save local copies of files when using the Web Client. The plugins.file.showFileSaveDialog works and allows users to specify the filename and location where the file should be downloaded/saved, however it does not warn if the file already exists and will be overwritten.

Is there a way to check this or a way to configure the displayed FileSave dialog to warn for existing files? In the Smart Client we can use the result from the showFileSaveDialog and check if the file already exists, but this is not possible in the Web Client.

Re: Warn for file overwrite when using showFileSaveDialog

PostPosted: Wed Oct 05, 2011 7:12 pm
by rossent
This is sample code which I found working for us:

Code: Select all
        //this is for downloading report export files to local files in web client!
        //this will be a file on the server
        var _exportFile = plugins.file.createTempFile('temp_report_export','.xls');
        if(exportFile)
        {
            //export the report to a file on the server
            plugins.jasperPluginRMI.runReport(_foundset, _reportFileName, _exportFile.getPath(), OUTPUT_FORMAT.XLS, _reportParamsObj);
            //read and "send" the report file to the web client
            var binData = plugins.file.readFile(_exportFile);
            //this will result in a standard "download" save operation in the Browser
            plugins.file.writeFile('report_data.xls',binData);
            //cleanup the temp file on the server
            plugins.file.deleteFile(_exportFile);
        }


This way the plugins.file.writeFile results in the browser triggering its default behavior of saving downloads which correctly warns if the user specifies a filename which already exists.

Re: Warn for file overwrite when using showFileSaveDialog

PostPosted: Thu Oct 06, 2011 4:00 pm
by jcompagner
writeFile is the way to go yes,
showFileSaveDialog cant work in a WebClient, that one is not web enabled.