[TOC] [Prev] [Next] [Bottom]



Chapter Seventeen

Reading, Writing, and Deleting Files


File Action

The File action allows you to read, write, and delete files on the Tango Server machine. Some of the functions you might want to perform using this action are as follows:

  • Store data permanently to disk for later retrieval (as opposed to variables which are in memory).
  • Keep a log file, appending to it when a certain function gets called in your application file.
  • Write HTML files using database-generated data to your Web server document folder.
  • Store data to a file for export to an external system, providing data navigation.
  • Import data from a file from an external system, for example, daily reports from a mainframe, newswire feeds, and periodic updates to a third-party supplier.
  • Use the action instead of giving FTP access to upload one or two files from a Web site.
  • Use the action as an administrative tool to upload graphics or as an intranet tool to upload word processor documents or other types of documents to the server.

The topics covered in this chapter include:

  • setting up a File action
  • handling file security.

[top] [back to top]


Setting Up a File Action

You can set up the three types of file operations using the File action.

  • Read (the default) allows you to specify the path and file name of the file you want to read. You also specify if you want to read the entire file or some part of it, and store the data in a local variable.
  • Write allows you to specify the path and file name of the file to write data to. You also specify what that data is and, if the file exists, whether the data should be appended to or overwrite the existing data. You can also store the file name in a local variable.
  • Delete allows you to specify the path and file name of the file you want to delete.

When you drag the File action icon from the Actions bar, the File action editing window appears.

!Note: For any of the editing fields, you can include value- returning Tango meta tags or drag snippets from the Snippets workspace. You can also right click an editing field to display a context-sensitive menu of editing commands, including the Insert Meta Tag command.


Setting Up Read Options

From the File Operation drop-down list, select Read, if it is not already selected.

The action editing window changes to show the options for the Read type operation, which you specify as follows:

  • File. The path and file name of the file you want to display to the user. You must specify the full, absolute path, not the path relative to the Web server root.
  • Read. Sets which part of the file to read. You can choose Entire file, or select one of the following options:
    • First. Type the number of bytes to read from the start of the file.
    • Last. Type the number of bytes to read at the end of the file.
    • Bytes. Type the starting and ending bytes. If the ending byte you are specifying is the end of the file, you can select EOF instead.
  • Store data in local variable. The name of a local variable to store the read data in.

    !Note: The read data is also available as <@COL 1> in the action's Results HTML and is stored in the local resultSet variable.


If you do not specify a file, the action does not do anything. In other words, the action behaves like a file exists, but the file is empty. Specifically, the specified variable is empty.

Setting Up Write Options

From the File Operation drop-down list, select Write.

The action editing window changes to show the options for the Write type operation.

Specify the Write options as follows:

  • File. The full, absolute path and file name of the file you want to write data to, for example:

c:\inetpub\wwwroot\client\uploads\mydoc.doc


!Note: This file information can also come from a variable or an argument.


You can also tell Tango to generate a temporary file by selecting Temporary file from the drop-down list. If you select this option, the server creates a temporary file using standard routines for the operating system.

  • Data to write. The data to write to the specified file. For example, you could enter the named post argument for a form field where the user enters the data to be saved in the specified file, or enters a file name to upload.
  • If file exists. Specify what you want to do if the file already exists. Select one of the following options:
    • Append to it appends to the existing file the data you are writing.
    • Overwrite it replaces the existing data in the file with the data you are writing.
    • Generate an error generates an error message on execution.
  • File Attributes (used by Mac OS servers only). These Mac OS only Type and Creator codes are used when creating a file. TEXT and R*ch are the default values for new actions. They are also the values used by the server if either field evaluates to empty. The server uses the first four characters of each field (after substitution). If you specify less than four characters, the value is space padded to the end.
  • Store file name in local variable. The name of a local variable in which to store the path and file name of the file written to. You would use this option when you write data to a temporary file.

!Note: The read data is also available as <@COL 1> in the action's Results HTML and is stored in the local resultSet variable.


Setting Up Delete Options

From the File Operation drop-down list, select Delete.

The action editing window changes to show the options for the Delete type operation.

In the File field, specify the full, absolute path and file name of the file to delete.

[top] [back to top]


Handling File Security

For more information, see "Configuring Tango Server".

File reads, writes and deletes are enabled in Tango by default. If you want to disable (or enable) these features, you can do so by changing the following options in the config.taf application file, in the Feature Switches screen:

fileReadSwitch
fileWriteSwitch
fileDeleteSwitch

For more information, see "Feature Switches".

Check or uncheck the check box beside the option.


!Note: The fileReadSwitch configuration variable also applies to the <@INCLUDE> meta tag.




[TOC] [Prev] [Next] [Bottom]



docs@pervasive.com

Copyright © 1998, Pervasive Software Inc. All rights reserved.