This documentation is archived and is not being maintained.

Opening Files for Sequential Access

Visual Studio .NET 2003

When you open a file for sequential access, you must specify whether to input characters from the file (Input mode), output characters to the file (Output mode), or append characters to the file (Append mode).

To open a file for sequential access

  • Use the FileOpen Function with the following syntax:
    FileOpen(FileNumber, FileName, OpenMode.Input)

When you open a sequential file for Input, the file must already exist; otherwise an error occurs. When you try to open a nonexistent file for Output or Append, however, the FileOpen statement creates the file first and then opens it.

After opening a file for an Input, Output, or Append operation, you must close it with the FileClose Function statement before reopening it for another type of operation.

Security Note   When writing to files, an application may need to create a file if the file to which it is trying to write does not exist. To do so, it needs permission for the directory in which the file is to be created. However, if the file already exists, the application only needs Write permission to the file itself. Wherever possible, it is more secure to create the file during deployment and only grant Write permission to that file, rather than to the entire directory. It is also more secure to write data to user directories than to the root directory or the Program Files directory.

See Also

Sequential File Access | Editing Files Opened for Sequential Access | File Access with Visual Basic Run-Time Functions | FileOpen Function | Random File Access | Binary File Access | Writing Strings to Sequential-Access Files