StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction StorageStreamTransaction Class


Represents a write transaction for a random-access stream.

public : sealed class StorageStreamTransaction : IClosable
struct winrt::Windows::Storage::StorageStreamTransaction : IClosable
public sealed class StorageStreamTransaction : IDisposable
Public NotInheritable Class StorageStreamTransaction Implements IDisposable
// 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.


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

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

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

Save the stream to the underlying file.

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

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

See also