Problem reading from text file in Smart Client

The following is a snippet of code from a method that writes a csv file attachment to the desktop (or, as you can see in the code, the app server) then reads it and then passes it to another method to be processed.

This method runs fine in Developer but errors out in the Smart Client (‘Problem reading text file’).

I am a bit stumped as to why this works in one and not the other…

if(utils.stringPatternCount(attachName.toLowerCase(),'.csv')){//if csv format
	var attachmentDataByteArray = attachment.getData();
	//write attachmentDataByteArray to a file...
	var desktop = plugins.file.getDesktopFolder();
	var fileName = desktop+'\/zz'+attachName;
	//var fileName = './server/webapps/ROOT/zz'+attachName; //also tried this path as well
	var success = plugins.file.writeFile(fileName,attachmentDataByteArray);
	if (success){ 
		var vTextFile = plugins.file.readTXTFile(fileName);
		if(!vTextFile){ plugins.dialogs.showWarningDialog('Warning', 'Problem reading text file', 'OK'); }
		else {
			UpdateStatusFromCSVReport(vTextFile);
			plugins.file.deleteFile(fileName);
		}
	}
	else { plugins.dialogs.showWarningDialog('Warning', 'Problem writing text file', 'OK'); }
}

Version 3.1.6-build 410
Java version 1.5.0_10-b03 (Windows XP)
MySQL 5

Hi Paul,

How big is this csv file and how much memory heap does the client have?

Client has max heap 128 and the file size is 1kb.

So it does write the file. Can you find the file on the desktop ?
Also do you see any errors in the server log ?

And maybe it’s a timing issue…that the file is still open, just a guess.
Try this.

if (success){ 
      application.sleep(1000); // wait a second.
      var vTextFile = plugins.file.readTXTFile(fileName);

Hope this helps.

Yeah, looks like it was the timing, I guess over the network it was taking a fraction longer to save and close the file before it could read it. Which would explain why it was working in developer (local to my PC) and not on the Production server.

Anyway, good idea, thanks.

That seems to be a bug in the file plugin, doesn’t it. The file should be closed before returning a result…