Storage​Stream​Transaction Storage​Stream​Transaction Storage​Stream​Transaction Class


Represents a write transaction for a random-access stream.

public sealed class StorageStreamTransaction : IClosable, IStorageStreamTransactionpublic sealed class StorageStreamTransaction : IDisposable, IStorageStreamTransactionPublic NotInheritable Class StorageStreamTransaction Implements IDisposable, IStorageStreamTransaction
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

Gets the random-access stream used in the transaction.

public IRandomAccessStream Stream { get; }public IRandomAccessStream Stream { get; }Public ReadOnly Property Stream As IRandomAccessStream


Close() Close() Close()

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

public void Close()This member is not implemented in C#This member is not implemented in VB.Net

CommitAsync() CommitAsync() CommitAsync()

Save the stream to the underlying file.

public IAsyncAction CommitAsync()public IAsyncAction CommitAsync()Public Function CommitAsync() As IAsyncAction

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++void Dispose()Sub Dispose

See Also