The function FileWriteFields reads values contained in a series of project tags or array elements, and then it writes those values to the fields of a CSV file .

Function Group Execution Windows Embedded Thin Client Mobile Access
FileWriteFields File Synchronous Supported Supported Not supported Not supported


Web Studio Help ctions file filewritefields.xml d406032e103 FileWriteFields
The file path and/or name of the CSV file to which the values will be written. If the file is located inside your project folder, you can specify either just the file name or the file path relative to that folder. If the file is located outside your project folder, you must specify the absolute file path.
The number of bytes to skip in the CSV file before writing values. To write to the start of the file, numOffset should be 0.

You can use this parameter to start writing to any position in the file, as long as you know how many bytes to skip. In most cases, you will simply take the value returned by the previous execution of this function (see “Returned value” below) and use it to resume writing where you previously stopped.

However, if you already know the structure of the file and where you want to start in it, you can do that. For example, if you know that each line of the file is exactly 100 bytes and you want to write to the start of the fifth line, numOffset should be 400.

You can also specify a value of -1, which will automatically append the values to the end of the file.

Note: The number of bytes per character in a file depends on the text encoding (i.e., ANSI, UTF-8, UTF-16, or other), the byte order, and the language or character set.
The name of the first project tag or array element in the series from which the function will read the values to be written to the CSV file. Project tags should be sequentially numbered with a numerical suffix, and the series is determined by incrementing that suffix (e.g., MyTag1, MyTag2, MyTag3, and so on). Array elements are handled similarly: the series is determined by incrementing the array index (e.g., MyArray[1], MyArray[2], MyArray[3], and so on). You do not need to begin the numbering with 1.
Note: If the tag name is not enclosed in quotes, the function will try to use the value of specified tag.
The number of project tags or array elements in the series to read. For example, if strStartTagName is MyTag4 and numNumberOfTags is 5, values will be read from the tags MyTag4, MyTag5, MyTag6, MyTag7, and MyTag8 and then written to the CSV file.

Returned value

If this function is successfully executed, it returns the position of the last byte written to the CSV file (including 0 if no bytes were written), which can be used in turn as the offset for the next batch of values to be written.

If this function fails, it returns a negative value.


“CSV” is an abbreviation of “comma-separated values”, and in most cases, a CSV file is simply a plain text file that uses commas (,) to delimit its data fields. Only comma delimiters — as opposed to tabs, spaces, pipes, or other characters — are supported in CSV files. Each field in the file can contain exactly one value, even if the value is empty.

When this function is executed, it will write at most one line of data. If a line feed is found before writing the specified number of tags, execution of the function will be aborted without writing any values.