Hi,
I checked the help content of the CREATETEMPFILE function and the file is deleted:
Microsoft Dynamics NAV Documentation
CREATETEMPFILE Function (File)
Creates a temporary file. This enables you to save data of any format to a temporary file. This file has a unique name and will be stored in a temporary file folder.
File.CreateTempFile
Parameters
File
Type: File
Use this variable to refer to the file.
You can use this function with NAME Function (File) and CLOSE Function (File).
This function is not supported in the RoleTailored client.
This example creates a temporary file with the text Hello and then deletes the file by using the File.CLOSE function. This example requires that you create the following variable.
Variable Data type
FileName
File
FileName.CREATETEMPFILE:
FileName.WRITE(‘Hello’);
FileName.CLOSE;
I will share with you some code I use to treat temporary files:
1. first create the file
You will need the following variables:
FilePath, type Text(250)
FileName, type Text(30)
Filesystem, type Record, subtype File
TextFile, type File
FilePath := TEMPORARYPATH; // check TEMPORARYPATH reference
Filesystem.Path := ‘’;
Filesystem.“Is a file” := TRUE;
Filesystem.Name := ‘LogFile.txt’;
FilePath := FilePath + Filesystem.Name;
// If you want you can check if the file already exists and deal with it: abort or overwrite the file.
TextFile.TEXTMODE(TRUE);
TextFile.WRITEMODE(TRUE);
TextFile.CREATE(FilePath);
2. Insert data:
TextFile.WRITE(‘some info I would like to share with you’);
3. Close file and display data
You will need the following variable:
ShellObject, type Automation, subtype ‘Microsoft Shell Controls And Automation’.Shell
TextFile.CLOSE;
CREATE(ShellObject, TRUE, TRUE); // check CREATE Function (Automation) reference
ShellObject.Open(FilePath); // this will use the system default viewer for the file type. Usually for txt files is notepad
// if it is csv file probably will open with MS Excel
Best Regards,
Jose.