0% found this document useful (0 votes)
3 views

complete-reference-vb_net_42

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

complete-reference-vb_net_42

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

File Enumerations

ReparsePoint This means the file contains a reparse point, which is a block of
[*]
user−defined data associated with a file or a directory.
SparseFile A sparse file is typically a large file whose data is mostly zeros.
System This means your file is part of the operating system or it is used exclusively
by the operating system.
Temporary A temporary file is usually a placeholder for a file currently in volatile
memory. Your application should delete temporary files as soon as they are
no longer needed.
[*]
The asterisk denotes that the facility may not be supported by all file systems.
Table 15−14: Constants for the FileMode Parameter

Member Description
Append Seeks to the end of the existing file when it is opened; if the file does not exist,
the file system creates a new file
Create Forces the creation of a new file
CreateNew Requests the file system to create a new file with the given name
Open Requests that the file system should open an existing file
OpenOrCreate Requests that the file system should open a file if it exists; otherwise, a new
file should be created
Truncate Requests that the file system should open an existing file
The following list demonstrates the use of these attributes in the File.Open methods:

• Append This attribute can only be used in conjunction with FileAccess.Write. Any attempt to read
in the same pass gets rebuked with ArgumentException. The following code demonstrates
FileMode.Append:

Dim noisefile As New FileStream(filePath, FileMode.Append, _


FileAccess.Read, FileShare.Read)
• Create If the file already exists, it will be overwritten. This requires PermissionAccess.Write and
FileIOPermissionAccess.Append. FileMode.Create is the equivalent of requesting that if the file
does not exist, use CreateNew; otherwise, use Truncate. The following code checks use File's Exist
method to choose either Create or CreateNew. There are various techniques you can use to prevent
inadvertent deletion of a file when trying to create a new one. The following If. . .Then condition is
one example:

If Not (File.Exists(FilePath)) Then


Dim noisefile As New FileStream(FilePath, FileMode.Create, _
FileAccess.Read, FileShare.Read)
End If
• CreateNew This attribute requires FileIOPermissionAccess.Read and
FileIOPermissionAccess.Append. This attribute provides better protection of existing files than the
Create attribute discussed earlier, because it will cause an IOException that prevents damage to the
existing file. The following examples illustrates its usage.

Dim noiseFile As New FileStream(filePath, FileMode.CreateNew, _


FileAccess.Read, FileShare.Read)
• Open This attribute also requires FileIOPermissionAccess.Read. It will cause a
FileNotFoundException if the file does not exist. The following examples demonstrates opening the
file in Read mode:

526

You might also like