FileRandomAccessStream FileRandomAccessStream FileRandomAccessStream FileRandomAccessStream Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Supports reading and writing to a file at a specified position.

public : sealed class FileRandomAccessStream : IClosable, IInputStream, IOutputStream, IRandomAccessStreampublic sealed class FileRandomAccessStream : IDisposable, IInputStream, IOutputStream, IRandomAccessStreamPublic NotInheritable Class FileRandomAccessStream Implements IDisposable, IInputStream, IOutputStream, IRandomAccessStream// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Properties

CanRead CanRead CanRead CanRead

Gets a value that indicates whether the stream can be read from.

public : PlatForm::Boolean CanRead { get; }public bool CanRead { get; }Public ReadOnly Property CanRead As bool// You can use this property in JavaScript.
Value
PlatForm::Boolean bool bool bool

True if the stream can be read from. Otherwise, false.

CanWrite CanWrite CanWrite CanWrite

Gets a value that indicates whether the file can be written to.

public : PlatForm::Boolean CanWrite { get; }public bool CanWrite { get; }Public ReadOnly Property CanWrite As bool// You can use this property in JavaScript.
Value
PlatForm::Boolean bool bool bool

True if the stream can be written to. Otherwise, false.

Position Position Position Position

Gets the byte offset of the stream.

public : ulong Position { get; }public ulong Position { get; }Public ReadOnly Property Position As ulong// You can use this property in JavaScript.
Value
ulong ulong ulong ulong

The number of bytes from the start of the stream.

Size Size Size Size

Gets or sets the size of the random access stream.

public : ulong Size { get; set; }public ulong Size { get; set; }Public ReadWrite Property Size As ulong// You can use this property in JavaScript.
Value
ulong ulong ulong ulong

The size of the stream.

Methods

CloneStream() CloneStream() CloneStream() CloneStream()

Creates a new instance of a IRandomAccessStream over the same resource as the current stream.

public : IRandomAccessStream CloneStream()public IRandomAccessStream CloneStream()Public Function CloneStream() As IRandomAccessStream// You can use this method in JavaScript.
Returns

The new stream. The initial, internal position of the stream is 0.

The internal position and lifetime of this new stream are independent from the position and lifetime of the cloned stream.

Close() Close() Close() Close()

Closes the current stream and releases system resources.

public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.

Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()

FlushAsync() FlushAsync() FlushAsync() FlushAsync()

Flushes data asynchronously in a sequential stream.

public : IAsyncOperation<PlatForm::Boolean> FlushAsync()public IAsyncOperation<bool> FlushAsync()Public Function FlushAsync() As IAsyncOperation( Of bool )// You can use this method in JavaScript.
Returns

The stream flush operation.

Remarks

The FlushAsync method may produce latencies and does not always guarantee durable and coherent storage of data. It's generally recommended to avoid this method if possible.

GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64)

Returns an input stream at a specified location in a stream.

public : IInputStream GetInputStreamAt(unsigned __int64 position)public IInputStream GetInputStreamAt(UInt64 position)Public Function GetInputStreamAt(position As UInt64) As IInputStream// You can use this method in JavaScript.
Parameters
position
unsigned __int64 UInt64 UInt64 UInt64

The location in the stream at which to begin.

Returns

GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64)

Returns an output stream at a specified location in a stream.

public : IOutputStream GetOutputStreamAt(unsigned __int64 position)public IOutputStream GetOutputStreamAt(UInt64 position)Public Function GetOutputStreamAt(position As UInt64) As IOutputStream// You can use this method in JavaScript.
Parameters
position
unsigned __int64 UInt64 UInt64 UInt64

The location in the output stream at which to begin.

Returns

OpenAsync(String, FileAccessMode) OpenAsync(String, FileAccessMode) OpenAsync(String, FileAccessMode) OpenAsync(String, FileAccessMode)

Prerelease. Opens a stream to an existing file given the file's path.

public : static IAsyncOperation<IRandomAccessStream> OpenAsync(PlatForm::String filePath, FileAccessMode accessMode)public static IAsyncOperation<IRandomAccessStream> OpenAsync(String filePath, FileAccessMode accessMode)Public Static Function OpenAsync(filePath As String, accessMode As FileAccessMode) As IAsyncOperation( Of IRandomAccessStream )// You can use this method in JavaScript.
Parameters
filePath
PlatForm::String String String String

A path to the file to be opened.

accessMode
FileAccessMode FileAccessMode FileAccessMode FileAccessMode

The permissions level to open the stream with.

Returns
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenAsync(String, FileAccessMode, StorageOpenOptions, FileOpenDisposition) OpenAsync(String, FileAccessMode, StorageOpenOptions, FileOpenDisposition) OpenAsync(String, FileAccessMode, StorageOpenOptions, FileOpenDisposition) OpenAsync(String, FileAccessMode, StorageOpenOptions, FileOpenDisposition)

Prerelease. Opens a stream to a file given a file path. If the file does not exist, it can be created using FileOpenDisposition.

public : static IAsyncOperation<IRandomAccessStream> OpenAsync(PlatForm::String filePath, FileAccessMode accessMode, StorageOpenOptions sharingOptions, FileOpenDisposition openDisposition)public static IAsyncOperation<IRandomAccessStream> OpenAsync(String filePath, FileAccessMode accessMode, StorageOpenOptions sharingOptions, FileOpenDisposition openDisposition)Public Static Function OpenAsync(filePath As String, accessMode As FileAccessMode, sharingOptions As StorageOpenOptions, openDisposition As FileOpenDisposition) As IAsyncOperation( Of IRandomAccessStream )// You can use this method in JavaScript.
Parameters
filePath
PlatForm::String String String String

A path to the file to be opened.

accessMode
FileAccessMode FileAccessMode FileAccessMode FileAccessMode

The permissions level to open the stream with.

sharingOptions
StorageOpenOptions StorageOpenOptions StorageOpenOptions StorageOpenOptions

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

openDisposition
FileOpenDisposition FileOpenDisposition FileOpenDisposition FileOpenDisposition

An action to take on the file.

Returns
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenForUserAsync(User, String, FileAccessMode) OpenForUserAsync(User, String, FileAccessMode) OpenForUserAsync(User, String, FileAccessMode) OpenForUserAsync(User, String, FileAccessMode)

Prerelease. Opens a stream for a user to an existing file given the file path and the user's information.

public : static IAsyncOperation<IRandomAccessStream> OpenForUserAsync(User user, PlatForm::String filePath, FileAccessMode accessMode)public static IAsyncOperation<IRandomAccessStream> OpenForUserAsync(User user, String filePath, FileAccessMode accessMode)Public Static Function OpenForUserAsync(user As User, filePath As String, accessMode As FileAccessMode) As IAsyncOperation( Of IRandomAccessStream )// You can use this method in JavaScript.
Parameters
user
User User User User

The user account for opening the stream.

filePath
PlatForm::String String String String

A path to the file to be opened.

accessMode
FileAccessMode FileAccessMode FileAccessMode FileAccessMode

The permissions level to open the stream with.

Returns
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenForUserAsync(User, String, FileAccessMode, StorageOpenOptions, FileOpenDisposition) OpenForUserAsync(User, String, FileAccessMode, StorageOpenOptions, FileOpenDisposition) OpenForUserAsync(User, String, FileAccessMode, StorageOpenOptions, FileOpenDisposition) OpenForUserAsync(User, String, FileAccessMode, StorageOpenOptions, FileOpenDisposition)

Prerelease. Opens a stream for a user to a file given a file path and the user's information. If the file does not exist, it can be created using FileOpenDisposition.

public : static IAsyncOperation<IRandomAccessStream> OpenForUserAsync(User user, PlatForm::String filePath, FileAccessMode accessMode, StorageOpenOptions sharingOptions, FileOpenDisposition openDisposition)public static IAsyncOperation<IRandomAccessStream> OpenForUserAsync(User user, String filePath, FileAccessMode accessMode, StorageOpenOptions sharingOptions, FileOpenDisposition openDisposition)Public Static Function OpenForUserAsync(user As User, filePath As String, accessMode As FileAccessMode, sharingOptions As StorageOpenOptions, openDisposition As FileOpenDisposition) As IAsyncOperation( Of IRandomAccessStream )// You can use this method in JavaScript.
Parameters
user
User User User User

The user account for opening the stream.

filePath
PlatForm::String String String String

A path to the file to be opened.

accessMode
FileAccessMode FileAccessMode FileAccessMode FileAccessMode

The permissions level to open the stream with.

sharingOptions
StorageOpenOptions StorageOpenOptions StorageOpenOptions StorageOpenOptions

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

openDisposition
FileOpenDisposition FileOpenDisposition FileOpenDisposition FileOpenDisposition

An action to take on the file.

Returns
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenTransactedWriteAsync(String) OpenTransactedWriteAsync(String) OpenTransactedWriteAsync(String) OpenTransactedWriteAsync(String)

Prerelease. Opens a stream for writing to an existing file given the file's path.

public : static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(PlatForm::String filePath)public static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(String filePath)Public Static Function OpenTransactedWriteAsync(filePath As String) As IAsyncOperation( Of StorageStreamTransaction )// You can use this method in JavaScript.
Parameters
filePath
PlatForm::String String String String

A path to the file to be opened.

Returns

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

Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenTransactedWriteAsync(String, StorageOpenOptions, FileOpenDisposition) OpenTransactedWriteAsync(String, StorageOpenOptions, FileOpenDisposition) OpenTransactedWriteAsync(String, StorageOpenOptions, FileOpenDisposition) OpenTransactedWriteAsync(String, StorageOpenOptions, FileOpenDisposition)

Prerelease. Opens a stream for writing to a file given a file path. If the file does not exist, it can be created using FileOpenDisposition.

public : static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(PlatForm::String filePath, StorageOpenOptions openOptions, FileOpenDisposition openDisposition)public static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(String filePath, StorageOpenOptions openOptions, FileOpenDisposition openDisposition)Public Static Function OpenTransactedWriteAsync(filePath As String, openOptions As StorageOpenOptions, openDisposition As FileOpenDisposition) As IAsyncOperation( Of StorageStreamTransaction )// You can use this method in JavaScript.
Parameters
filePath
PlatForm::String String String String

A path to the file to be opened.

openOptions
StorageOpenOptions StorageOpenOptions StorageOpenOptions StorageOpenOptions

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

openDisposition
FileOpenDisposition FileOpenDisposition FileOpenDisposition FileOpenDisposition

An action to take on the file.

Returns

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

Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenTransactedWriteForUserAsync(User, String) OpenTransactedWriteForUserAsync(User, String) OpenTransactedWriteForUserAsync(User, String) OpenTransactedWriteForUserAsync(User, String)

Prerelease. Opens a writable stream for a user to an existing file given the file's path and the user's information.

public : static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteForUserAsync(User user, PlatForm::String filePath)public static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteForUserAsync(User user, String filePath)Public Static Function OpenTransactedWriteForUserAsync(user As User, filePath As String) As IAsyncOperation( Of StorageStreamTransaction )// You can use this method in JavaScript.
Parameters
user
User User User User

The user account for opening the stream.

filePath
PlatForm::String String String String

A path to the file to be opened.

Returns

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

Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

OpenTransactedWriteForUserAsync(User, String, StorageOpenOptions, FileOpenDisposition) OpenTransactedWriteForUserAsync(User, String, StorageOpenOptions, FileOpenDisposition) OpenTransactedWriteForUserAsync(User, String, StorageOpenOptions, FileOpenDisposition) OpenTransactedWriteForUserAsync(User, String, StorageOpenOptions, FileOpenDisposition)

Prerelease. Opens a writable stream for a user to a file given a file path and the user's information. If the file does not exist, it can be created using FileOpenDisposition.

public : static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteForUserAsync(User user, PlatForm::String filePath, StorageOpenOptions openOptions, FileOpenDisposition openDisposition)public static IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteForUserAsync(User user, String filePath, StorageOpenOptions openOptions, FileOpenDisposition openDisposition)Public Static Function OpenTransactedWriteForUserAsync(user As User, filePath As String, openOptions As StorageOpenOptions, openDisposition As FileOpenDisposition) As IAsyncOperation( Of StorageStreamTransaction )// You can use this method in JavaScript.
Parameters
user
User User User User

The user account for opening the stream.

filePath
PlatForm::String String String String

A path to the file to be opened.

openOptions
StorageOpenOptions StorageOpenOptions StorageOpenOptions StorageOpenOptions

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

openDisposition
FileOpenDisposition FileOpenDisposition FileOpenDisposition FileOpenDisposition

An action to take on the file.

Returns

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

Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions)

Returns an asynchronous byte reader object.

public : IAsyncOperationWithProgress<IBuffer, unsigned int> ReadAsync(IBuffer buffer, unsigned int count, InputStreamOptions options)public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)Public Function ReadAsync(buffer As IBuffer, count As UInt32, options As InputStreamOptions) As IAsyncOperationWithProgress( Of IBuffer, uint )// You can use this method in JavaScript.
Parameters
buffer
IBuffer IBuffer IBuffer IBuffer

The buffer into which the asynchronous read operation places the bytes that are read.

count
unsigned int UInt32 UInt32 UInt32

The number of bytes to read that is less than or equal to the Capacity value.

options
InputStreamOptions InputStreamOptions InputStreamOptions InputStreamOptions

Specifies the type of the asynchronous read operation.

Returns

Seek(UInt64) Seek(UInt64) Seek(UInt64) Seek(UInt64)

Sets the position of the stream to the specified value.

public : void Seek(unsigned __int64 position)public void Seek(UInt64 position)Public Function Seek(position As UInt64) As void// You can use this method in JavaScript.
Parameters
position
unsigned __int64 UInt64 UInt64 UInt64

The new position of the stream.

WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer)

Writes data asynchronously to a file.

public : IAsyncOperationWithProgress<unsigned int, unsigned int> WriteAsync(IBuffer buffer)public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)Public Function WriteAsync(buffer As IBuffer) As IAsyncOperationWithProgress( Of uint, uint )// You can use this method in JavaScript.
Parameters
buffer
IBuffer IBuffer IBuffer IBuffer

The buffer into which the asynchronous writer operation writes.

Returns

The byte writer operation.