Saving file to client location

Hi all,

I have build a web application, where the it2be word plugin is generating a word document.

Now I want the user/client to choose the save location.
plugins.file.showFileSaveDialog = not web enabled getting headles exception errors.

plugins.it2be_word.save(‘c:/test.docx’) = saving to the server c: drive

plugins.it2be_word.save(plugins.file.showFileSaveDialog(plugins.file.getDesktopFolder())) = working but only from a local servoy instance.

Any help is welcome.
Tnx in advance

Derk

Servoy 7.3.1
Java v7

You cant save a file directly to local drive of a user using webclient. You can do plugins.file.writeFile… so the file will present as a download

Hi Harjo,
Tnx for the reply. I have tried 2 things but only got errors.

1 .
I have tried the writeFile method
writeFile(‘report.docx’, plugins.it2be-word.documentobject)
I got the following error.
Can’t find method com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(string,com.it2be.word.IWDocument,string).

When I let the it2be plugin save the document first to
var _savelocation = ‘…/application_server/w_docs/report.docx’;
_document.save( _savelocation);
Then I added a download button with the following code:
var _pathto = “…/application_server/w_docs/”;
var _repname = ‘report.docx’;
var _reportfilename = _pathto + _repname;
var _f = plugins.file.convertToJSFile(_reportfilename)
if(_f && _f.canRead()){
plugins.file.writeFile(‘report.docx’, _f , ‘application/vnd.openxmlformats-officedocument.wordprocessingml.document’)
} else {
application.output(‘cant read file’)
}

Error: Can’t find method com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(string,com.servoy.extensions.plugins.file.JSFile,string)

Think I am missing something here, or just having a bad day :D

got it:

I mixed up that the file wasnt read as bytes. Instead of making a byte array.

Tnx for the advice

Working code example:
var bytes = new Array();
for (var i=0; i<10240; i++)
bytes = i % 100;
var _pathto = “…/application_server/w_docs/”;
var _repname = ‘report.docx’;
var _reportfilename = _pathto + _repname;
var _f = plugins.file.convertToJSFile(_reportfilename)
if(_f && _f.canRead()){

  • plugins.file.writeFile(‘report.docx’, bytes , ‘application/vnd.openxmlformats-officedocument.wordprocessingml.document’)*
  • } else {*
  • application.output(‘cant read file’)*
  • }*

strange way of reading a file as bytes!

just use: plugins.file.readFile…

Everything works fine now… tnx Harjo for the advice