StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction Class


Represents a write transaction for a random-access stream.

public : sealed class StorageStreamTransaction : IClosable, IStorageStreamTransaction
struct winrt::Windows::Storage::StorageStreamTransaction : IClosable, IStorageStreamTransaction
public sealed class StorageStreamTransaction : IDisposable, IStorageStreamTransaction
Public NotInheritable Class StorageStreamTransaction Implements IDisposable, IStorageStreamTransaction
// This class does not provide a public constructor.
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


The File Access sample shows you how to use a StorageStreamTransaction object to perform a transacted write operation on a file.

    if (file != null)
        using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync())
            using (DataWriter dataWriter = new DataWriter(transaction.Stream))
                dataWriter.WriteString("Swift as a shadow");
                transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file
                await transaction.CommitAsync();
// Use catch blocks to handle errors
catch (FileNotFoundException)
    // For example, handle a file not found error

if ( file !== null) {
        function (transaction) {
            var dataWriter = new Windows.Storage.Streams.DataWriter(;
            dataWriter.writeString("Swift as a shadow");
            dataWriter.storeAsync().then(function (size) {
       = size; // reset stream size to override the file
                transaction.commitAsync().done(function () {
                    // Text written to file

                    // Close stream
        // Handle errors with an error function
        function (error) {
            // Proccess errors

In the example, file is a local variable that contains a storageFile that represents the file to write.


Stream Stream Stream Stream Stream

Gets the random-access stream used in the transaction.

public : IRandomAccessStream Stream { get; }
IRandomAccessStream Stream();
public IRandomAccessStream Stream { get; }
Public ReadOnly Property Stream As IRandomAccessStream
var iRandomAccessStream =;


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

Releases system resources that are exposed by the stream, indicating that the data request is complete.

public : void Close()
void Close() const;
// This member is not implemented in C#
' This member is not implemented in VB.Net
// This member is not implemented in JavaScript

CommitAsync() CommitAsync() CommitAsync() CommitAsync() CommitAsync()

Save the stream to the underlying file.

public : IAsyncAction CommitAsync()
IAsyncAction CommitAsync() const;
public IAsyncAction CommitAsync()
Public Function CommitAsync() As IAsyncAction
Windows.Storage.StorageStreamTransaction.commitAsync().done( /* Your success and error handlers */ );

No object or value is returned by this method.

Dispose() Dispose() Dispose()

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

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

See Also