IStorageFile2.OpenAsync(FileAccessMode, StorageOpenOptions) Method

Definition

Opens a random-access stream over the file.

public:
 IAsyncOperation<IRandomAccessStream ^> ^ OpenAsync(FileAccessMode accessMode, StorageOpenOptions options);
/// [Windows.Foundation.Metadata.Overload("OpenWithOptionsAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode const& accessMode, StorageOpenOptions const& options);
[Windows.Foundation.Metadata.Overload("OpenWithOptionsAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options);
function openAsync(accessMode, options)
Public Function OpenAsync (accessMode As FileAccessMode, options As StorageOpenOptions) As IAsyncOperation(Of IRandomAccessStream)

Parameters

accessMode
FileAccessMode

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

options
StorageOpenOptions

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

Returns

IAsyncOperation<IRandomAccessStream>

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

Attributes

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.

Applies to