IStorageFile2.OpenAsync(FileAccessMode, StorageOpenOptions) IStorageFile2.OpenAsync(FileAccessMode, StorageOpenOptions) IStorageFile2.OpenAsync(FileAccessMode, StorageOpenOptions) IStorageFile2.OpenAsync(FileAccessMode, StorageOpenOptions) IStorageFile2.OpenAsync(FileAccessMode, StorageOpenOptions) Method

Definition

Opens a random-access stream over the file.

public : IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options)
IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options) const;
public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options)
Public Function OpenAsync(accessMode As FileAccessMode, options As StorageOpenOptions) As IAsyncOperation(Of IRandomAccessStream)
Windows.Storage.IStorageFile2.openAsync(accessMode, options).done( /* Your success and error handlers */ );

Parameters

accessMode
FileAccessMode FileAccessMode FileAccessMode

One of the enumeration values that specifies the type of access to allow.

options
StorageOpenOptions StorageOpenOptions StorageOpenOptions

A bitwise combination of the enumeration values that specify options for opening the stream.

Returns

When this method completes, it returns an IRandomAccessStream that contains the requested random-access stream.

Remarks

If you simply want to open a file in your app, see the OpenAsync method of the StorageFile class.

Using this method, a file can be accessed by both file readers and writers simultaneously. The following is a table describing the situations for various parameter settings of FileAccessMode and StorageOpenOptions:

FileAccessMode
StorageOpenOptions Read ReadWrite
None A reader which is lower priority than a writer. If a write occurs, this low priority reader will fail. This is a single writer. The file cannot be opened if OpenAsync(Read, AllowOnlyReaders) has been used, and it will prevent a new OpenAsync(Read, AllowOnlyReaders) from being used.
AllowOnlyReaders A reader which can only exist with other readers. If an open is attempted with a writer, it will fail. This is a single writer. The file cannot be opened if OpenAsync(Read, AllowOnlyReaders) has been used, and it will prevent a new OpenAsync(Read, AllowOnlyReaders) from being used.
AllowReadersAndWriters A reader which can exist with other readers and writers simultaneously. This writer will invalidate low priority readers when a write occurs and can coexist with other readers and writers.