StorageStreamTransaction
StorageStreamTransaction
StorageStreamTransaction
StorageStreamTransaction
Class
Definition
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// 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)
|
Examples
The File Access sample shows you how to use a StorageStreamTransaction object to perform a transacted write operation on a file.
try
{
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) {
file.openTransactedWriteAsync().then(
function (transaction) {
var dataWriter = new Windows.Storage.Streams.DataWriter(transaction.stream);
dataWriter.writeString("Swift as a shadow");
dataWriter.storeAsync().then(function (size) {
transaction.stream.size = size; // reset stream size to override the file
transaction.commitAsync().done(function () {
// Text written to file
// Close stream
transaction.close();
});
});
},
// 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.
Properties
Methods
Close() 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// You can use this method in JavaScript.
CommitAsync() CommitAsync() CommitAsync() CommitAsync()
Save the stream to the underlying file.
public : IAsyncAction CommitAsync()public IAsyncAction CommitAsync()Public Function CommitAsync() As IAsyncAction// You can use this method in JavaScript.
Returns
No object or value is returned by this method.