writeFile, What am I doing wrong??

I am trying to write a text (html) file to the desktop of the client which will be opened by Excel as a way of exporting data to excel where the user can choose some more understandable field names, and also so that I can get image blobs out and into excel. I will loop through the foundset to populate my html.

My method ends with this:

		v_raw_html += "</table></body></html>"	 

var f = plugins.file.convertToJSFile(v_raw_html);
		
var path = plugins.file.getHomeDirectory()

path = path.getAbsolutePath();

var v_date_today = utils.dateFormat(new Date,'ddMMyy')

var export_to_file = path + '/Desktop/' + v_date_today + 'export.htm'

   	if (!f.exists()){
	plugins.file.writeFile(export_to_file,f)
   	}

There is more to v_raw_html before this, but that all works

Problem is I get this error when I try to run it:

Can’t find method com.servoy.extensions.plugins.file.FileProvider.js_writeFile(org.mozilla.javascript.CharSequenceBuffer,com.servoy.extensions.plugins.file.JSFile). (/Applications/Servoy/servoy_workspace/art/forms/export_dialog.js#206)
Can’t find method com.servoy.extensions.plugins.file.FileProvider.js_writeFile(org.mozilla.javascript.CharSequenceBuffer,com.servoy.extensions.plugins.file.JSFile). (/Applications/Servoy/servoy_workspace/art/forms/export_dialog.js#206)
at /Applications/Servoy/servoy_workspace/art/forms/export_dialog.js:206 (export_to_html_and_close)
at /Applications/Servoy/servoy_workspace/art/forms/artwork.js:663 (show_export_dialog)

I have no idea what I’m doing wrong… Please help…

Thanks

Bevil

f is a JSFile not a byte

try f.readFile()

Thanks Michael.

Do you mean like this:

	plugins.file.writeFile(export_to_file,  plugins.file.readFile(f))

Yes you’re right, it’s not a method of the JSFile object.

Unfortunately that doesn’t work either…

I wish there was some easy to find documentation on taking a string in a var, and writing it to a file on the filesystem… I have even done this previously using Servoy’s built in streaming, the datastream plugin, and the UserManager Pro plugin, none of them caused a problem before but this time, I just can’t make it work… The difference now is that I am using a string rather than a blob to write to the filesystem…

Oh well, I’ll keep fighting my way through it… :)

Bevil

Why not use writeTXTFile?

var _s = "file content"
var _fn = "test.txt"
plugins.file.writeTXTFile(plugins.file.convertToJSFile(_fn), _s)

Thank you very much Michael. I will give that a go…

The resulting file will actually be an htm file for Excel to read, but I can’t see a reason why using text would not work and giving it the appropriate file extension… I will try it.

Thank you

Bevil

also, can var _s = my var string?