FileIO.WriteBufferAsync(IStorageFile, IBuffer) FileIO.WriteBufferAsync(IStorageFile, IBuffer) FileIO.WriteBufferAsync(IStorageFile, IBuffer) FileIO.WriteBufferAsync(IStorageFile, IBuffer) FileIO.WriteBufferAsync(IStorageFile, IBuffer) Method

Definition

Writes data from a buffer to the specified file.

public : static IAsyncAction WriteBufferAsync(IStorageFile file, IBuffer buffer)
static IAsyncAction WriteBufferAsync(IStorageFile file, IBuffer buffer) const;
public static IAsyncAction WriteBufferAsync(IStorageFile file, IBuffer buffer)
Public Shared Function WriteBufferAsync(file As IStorageFile, buffer As IBuffer) As IAsyncAction
Windows.Storage.FileIO.writeBufferAsync(file, buffer).done( /* Your success and error handlers */ );

Parameters

file
IStorageFile IStorageFile IStorageFile

The file that the buffer of data is written to.

buffer
IBuffer IBuffer IBuffer

The buffer that contains the data to write.

Returns

No object or value is returned when this method completes.

Examples

The File Access sample shows you how to use WriteBufferAsync to write data from a buffer to a file.


try
{
    if (file != null)
    {
        IBuffer buffer = CryptographicBuffer.GenerateRandom(10);
        await FileIO.WriteBufferAsync(file, buffer);
        // Perform additional tasks after file is written
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}

if (file !== null) {
    // Create buffer
    var buffer = Windows.Security.Cryptography.CryptographicBuffer.generateRandom(10);

    // Write buffer to file
    Windows.Storage.FileIO.writeBufferAsync(file, buffer).done(function () {
        // Perform additional tasks after file is written
    },
    // Handle errors with an error function
    function (error) {
        // Handle errors encountered during write
    });
}

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

Although the writeBufferAsync methods don't have a return value, you can still perform additional tasks after the text is written to the file, as the example shows.