IStorageFile2 IStorageFile2 IStorageFile2 IStorageFile2 Interface

Definition

Represents a file. Provides information about the file and its contents, and ways to manipulate them.

Important

If you simply want to work with files in your app, see the StorageFile class.

public : interface IStorageFile2public interface IStorageFile2Public Interface IStorageFile2// You can use this interface in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Methods

OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions)

Opens a random-access stream over the file.

public : IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options)public IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode, StorageOpenOptions options)Public Function OpenAsync(accessMode As FileAccessMode, options As StorageOpenOptions) As IAsyncOperation( Of IRandomAccessStream )// You can use this method in JavaScript.
Parameters
accessMode
FileAccessMode FileAccessMode FileAccessMode FileAccessMode

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

options
StorageOpenOptions StorageOpenOptions StorageOpenOptions StorageOpenOptions

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

Returns

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.

OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions)

Opens a random-access stream to the file that can be used for transacted-write operations with the specified options.

public : IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(StorageOpenOptions options)public IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(StorageOpenOptions options)Public Function OpenTransactedWriteAsync(options As StorageOpenOptions) As IAsyncOperation( Of StorageStreamTransaction )// You can use this method in JavaScript.
Parameters
options
StorageOpenOptions StorageOpenOptions StorageOpenOptions StorageOpenOptions

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

Returns

When this method completes, it returns a StorageStreamTransaction containing the random-access stream and methods that can be used to complete transactions.

Remarks

This method results in a stream that writes to a temporary file, then atomically commits the writes to the actual file by renaming the temporary file onto the actual file. Because of how the stream writing works, a transacted writer cannot coexist with another writer, meaning StorageOpenOptions.AllowReadersAndWriters is not valid for this method and will return E_INVALIDARG if used.