FileWrite

FileWrite is a built-in function that writes a string to a specified text file. If the file does not exist, it will be created when the function is executed.

Function Group Execution Windows Embedded Thin Client Mobile Access
FileWrite File Synchronous Supported Supported Supported (see “Notes” below) Not supported

Syntax

  FileWrite(strFileName,strWriteText,optNumAppend)  
Web Studio Help cs2ffunctions file filewrite.xml d405235e112 FileWrite
strFileName
The name of the text file.

By default, the file must be located in your project folder (i.e., the folder that contains the file projectname.APP), on the computer that host the project runtime server. If the file is or should be located in another folder, specify the complete file path.

strWriteText
The text to be written to the file.
optNumAppend
A numerical flag indicating how the text should be written to the file:
Value Description
0 Create a new ASCII file with the specified file name. If the file already exists, overwrite it.
1 Append to an existing ASCII file with the specified file name. If the file does not exist, create it.
2 Create a new Unicode (UTF-16LE) file with the specified file name. If the file already exists, overwrite it.
3 Append to an existing Unicode (UTF-16LE) file with the specified file name. If the file does not exist, create it.

This parameter is optional; if no value is specified, or if the specified value is not one of the accepted values described in the table above, the default value is 0.

Returned value

This function returns one of the following possible values:
Value Description
0 Function successfully executed.
-1 Invalid parameter(s).
-2 Failed to open file. Either the drive is write-protected or the file name is invalid.

Notes

If this function is called in a project screen on a thin client, it will still write to the specified file in the project folder on the computer that hosts the project runtime server. You cannot use this function to write to a file on the thin client.

Examples

Create a new ASCII file in the project folder:
  FileWrite("est.txt","This is a test.")  
Append to an existing ASCII file in the project folder:
  FileWrite("est.txt","This is a test.",1)  
Append to an existing Unicode file in the Documents folder:
  FileWrite("C:UsersMyUserDocumentsest.txt","This is a test.",3)  

FileWrite