Warn for file overwrite when using showFileSaveDialog

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

Warn for file overwrite when using showFileSaveDialog

Postby rossent » Wed Oct 05, 2011 6:06 pm

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.
Rossen Totev
Argos Software
rossent
 
Posts: 288
Joined: Wed Dec 31, 2008 2:03 pm

Re: Warn for file overwrite when using showFileSaveDialog

Postby rossent » Wed Oct 05, 2011 7:12 pm

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.
Rossen Totev
Argos Software
rossent
 
Posts: 288
Joined: Wed Dec 31, 2008 2:03 pm

Re: Warn for file overwrite when using showFileSaveDialog

Postby jcompagner » Thu Oct 06, 2011 4:00 pm

writeFile is the way to go yes,
showFileSaveDialog cant work in a WebClient, that one is not web enabled.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Web Development

Who is online

Users browsing this forum: No registered users and 4 guests

cron