Freigeben über


FileAccess Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Defines constants for read, write, or read/write access to a file.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration FileAccess
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum FileAccess

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Read Read access to the file. Data can be read from the file. Combine with Write for read/write access.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Write Write access to the file. Data can be written to the file. Combine with Read for read/write access.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 ReadWrite Read and write access to the file. Data can be written to and read from the file.

Remarks

Specify a FileAccess parameter in IsolatedStorageFileStream constructors.

Examples

The following example accesses a file for writing. This code example is part of a larger example provided for the IsolatedStorageFile class.

' Write to an existing file: MyApp1\SubDir1\MyApp1A.txt

' Determine if the file exists before writing to it.
Dim filePath As String = Path.Combine(subdirectory1, "MyApp1A.txt")

If store.FileExists(filePath) Then
    Try
        Using sw As StreamWriter = _
            New StreamWriter(store.OpenFile(filePath, FileMode.Open, FileAccess.Write))

            sw.WriteLine("To do list:")
            sw.WriteLine("1. Buy supplies.")
        End Using

    Catch ex As IsolatedStorageException
        sb.AppendLine(ex.Message)
    End Try
Else
    sb.AppendLine((filePath + "does not exist"))
End If
// Write to an existing file: MyApp1\SubDir1\MyApp1A.txt

// Determine if the file exists before writing to it.
string filePath = Path.Combine(subdirectory1, "MyApp1A.txt");

if (store.FileExists(filePath))
{
    try
    {
        using (StreamWriter sw =
            new StreamWriter(store.OpenFile(filePath,
                FileMode.Open, FileAccess.Write)))
        {
            sw.WriteLine("To do list:");
            sw.WriteLine("1. Buy supplies.");
        }
    }
    catch (IsolatedStorageException ex)
    {

        sb.AppendLine(ex.Message);
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.