Write Text to File Action

image\Actions_Storage_Write_Text_File.jpg

The Write Text to File action allows you to store a specific piece of text information into a disk file. A disk file is a plain text file (a file with the .txt file extension).

Note:
You can write to the same disk file as often as you like. In other words, information from a variety of variables (or even the same variable which may have new data in it) can be appended to the end of the disk file. Alternatively, new data can overwrite the existing data on the disk file.

There is also a Write to Disk File Action if you want to copy the contents of a variable to a disk file.

Setting up the Write Text to File Action:

1. Add the Write Text to File action to your trigger, as described in adding actions. The Write Text to File tab will automatically appear when you add the action.

2. Click inside the Source box and type the text you want to store in the text file.

Note:
Words will automatically wrap to the next line when you reach the end of the box. Alternatively, you can press the Enter key on the keyboard to start a new line in the Source box. There is no limit to the number of words you enter in this box.

3. Click on the down arrow to the right of the Filename option, to select the name of the disk file you want to store the information in. Alternatively, use the Browse… button to locate an existing file on a disk. The full pathname of the file you enter in this box is shown in the Filename field.

 You can enter variables into the Filename field – the variable should contain a valid pathname for the file (see Using variables to create pathnames for more information).

 If the name of the file you enter does not exist, the file will be created when this action is triggered in the publication.

The file can be on a hard disk, a networked drive or floppy disk. If the network or floppy disk is not available when the publication is run, no warning message will appear and the data is not stored.

4. Tick the Store in Windows TEMP directory option if you want to use the Temp directory in Windows rather than create your own folder in which to store the file. By default this checkbox is not ticked.

Note:
Opus can always find out where the TEMP directory is located on any computer and it will always be in a location that can be written to. If you use this option, the Filename field should only contain the name of the text file and not a pathname e.g. results.txt is correct while c:\studentFolder\results.txt would be incorrect.

5. Use the Overwrite existing contents option if you want to delete the current contents of the text file and replace it with the contents of the variable you have entered in the Variable field.

6. Use the Add to existing contents option if you want to add the new information to the file.

Note:
Selecting this option will make the following options available: Start new line, Comma separated and Use quote marks checkboxes.

7. Click the Start new line option if you want the new information to start on a new line in the text file.

8. Click the Comma separated option if you want to place a comma after the new information you add to the file.

9. Click the Use quote marks option if you want to surround the new information added to the text file with quote marks.

Note:
These three options are particularly useful if you later decide to use this file in a database, spreadsheet or listed in a table in a text document because most word processing, spreadsheet and database applications allow you to import ‘comma separated’ or ‘quote mark’ text as separate fields so they can be easily lined-up in cells, columns or rows.

10. Click on the Encrypt Data option if you want to stop your data from been easily read by someone else. Ticking this checkbox will enable the Key field. In the Key field type a key (similar to a password) in the edit box provided.

 The key can be any combination of letters and numbers in both uppercase and lowercase. We recommend the key is more than six characters. You will need to remember this key or you will not be able to read the information from the file again.

If you do not enter a key, Opus will use its own default key to encrypt the data. When you use the Read from disk file action to read data from the file, you must ensure that you leave the Key edit box blank.

11. Click on the Apply button to save your changes.

Note:
This action will only work for publications that you have published using the Create a Standalone Publication option in the Publish Wizard.

Related Topics:

Introducing the Storage Actions

Restrictions Reading and Writing Disk Files

Using Variables to Create Pathnames

Disk Files vs Windows Registry

the Read from Disk File action