OnPreDataItem=BEGIN tpath := 'C:\Users\User\Documents\'; tFilename := tpath + 'listing-'+ FORMAT(TODAY,0,'<day,2>-<month,2>-<year,2>')+ FORMAT(TIME, 0, '<hour,2><minute,2><second,2>') +'.' + 'csv'; CLEAR(fFileToExport); CLEAR(objFileSystem); CREATE(objFileSystem, TRUE, TRUE); IF NOT objFileSystem.FileExists(tFilename) THEN fFileToExport.CREATE(tFilename) ELSE BEGIN fFileToExport.TEXTMODE(TRUE); fFileToExport.OPEN(tFilename); END; CLEAR(objFileSystem); fFileToExport.TEXTMODE(TRUE); fFileToExport.WRITEMODE(TRUE); fFileToExport.WRITE(';;"Test Column 3"'); END; OnAfterGetRecord=BEGIN fFileToExport.WRITEMODE(TRUE); fFileToExport.TEXTMODE(TRUE); fFileToExport.WRITE('test 2'); END; OnPostDataItem=BEGIN CLEAR(fFileToExport); END; }Thanks in advance for your help
Answers
http://mibuso.com/blogs/davidmachanick/
If your file isn't open in another application check whether your OPEN gets called muliple times for some reason.
If that doesn't happen restart the service on your DEV Machine. Had that happen multiple times that NAV leaves files open for an eternity if you don't close them properly.
The code is in the root dataitem.
fFileToExport.WRITEMODE(TRUE);
fFileToExport.TEXTMODE(TRUE);
should be used before File.OPEN is used to open the file. If you use this function on a file that is already open, then an error occurs.
+ the fact that i didn't have to use the writemode function any longer.
Thanks for the help all.