Open


The Open method opens or creates file in access mode compatible with mode of operation of the object. Currently attached file is detached, flushing its data buffer and closing it if necessary.
C++
long Open(
  LPSTR FileName,                         // file name
  BOOL Create = FALSE,                    // creation flag
  BOOL Truncate = FALSE,                  // truncation flag
  long Timeout = 5                        // timeout
);
long Open(
  LPWSTR FileName,                        // file name
  BOOL Create = FALSE,                    // creation flag
  BOOL Truncate = FALSE,                  // truncation flag
  long Timeout = 5                        // timeout
);
BASIC
Open(
  FileName As Variant,                    // file name
  Create As Boolean = False,              // creation flag
  Truncate As Boolean = False,            // truncation flag
  Timeout As Long = 5                     // timeout
) As Long

Parameters

FileName
C++
Pointer to buffer containing name of the file (must be NULL terminated).
BASIC
Variant containing name of the file.
Variant must be of String data type; it must not be an array.
Create
If this parameter is TRUE, file is created if does not exist.
If this parameter is FALSE and file does not exist, method returns with error.
Truncate
If this parameter is TRUE and file exists, it is truncated to zero size.
If file does not exist this parameter is ignored.
Timeout
Time to wait for opening if file is used exclusively by another application or thread, in seconds.
If this parameter is 0 and opening is not possible method returns immediately with error.

Return Values

If the method succeeds, the return value is 0.
If the method fails, the return value is failure code and error code is set. Call GetError to get error code.

Remarks

FileName specifies name of the file given as relative or absolute path; if relative path is specified GetName method can be called to obtain fully qualified path.

File access mode is determined by mode of operation of the object as shown below:

OBJECT FILE

IXF_MODE_READ IXF_FILE_READ

IXF_MODE_WRITE IXF_FILE_WRITE

IXF_MODE_RDWR IXF_FILE_RDWR


File sharing mode is determined by mode of operation of the object as shown below:

OBJECT FILE

IXF_MODE_READ IXF_FILE_SHARE_READ

IXF_MODE_READ +
IXF_MODE_READLOCK
IXF_FILE_SHARE_RDWR

IXF_MODE_WRITE 0 (not shared)

IXF_MODE_WRITE +
IXF_MODE_WRITELOCK
IXF_FILE_SHARE_RDWR

IXF_MODE_RDWR +
IXF_MODE_WRITELOCK
IXF_FILE_SHARE_READ

IXF_MODE_RDWR +
IXF_MODE_RDWRLOCK
IXF_FILE_SHARE_RDWR

Method can be used whenever file access and share mode can be solely determined by mode of operation of the object. Developer does not have to specify access mode and other file related parameters because these parameters result from mode of operation of the object specified during initialization. This means that you do not have direct control over file access mode; if file must be opened in specific access or share mode that cannot be achieved with Open method, OpenAdvanced should be used instead. For example, if file must be opened for shared access with manual locking only, Open method cannot be used because it opens file for exclusive access.

On completion internal object settings are set to default values. Active buffer is set to its maximum size, read and write counters are reset to zero, data buffers are cleared. File position is set at the beginning of the file (0).

Unicode version of the method should not be confused with Unicode system calls or Unicode text data. All versions of the method can be used on Unicode and non-Unicode systems depending on your needs. On Unicode systems, however, file is opened by Unicode version of system function (unless Unicode is disabled with EnableUnicode method). Conversion between ANSI and Unicode is performed internally according to current codepage which can be changed with SetCodePage method. See Unicode Support for more information on Unicode system calls, Unicode methods and Unicode text data.

See Also

OpenAdvanced, Attach, Close, GetName, GetFile, Opening and Attaching File