Share via


FileIO.WriteBufferAsync(IStorageFile, IBuffer) Method

Definition

Writes data from a buffer to the specified file.

public:
 static IAsyncAction ^ WriteBufferAsync(IStorageFile ^ file, IBuffer ^ buffer);
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncAction WriteBufferAsync(IStorageFile const& file, IBuffer const& buffer);
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncAction WriteBufferAsync(IStorageFile file, IBuffer buffer);
function writeBufferAsync(file, buffer)
Public Shared Function WriteBufferAsync (file As IStorageFile, buffer As IBuffer) As IAsyncAction

Parameters

file
IStorageFile

The file that the buffer of data is written to.

buffer
IBuffer

The buffer that contains the data to write.

Returns

No object or value is returned when this method completes.

Attributes

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
}

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.

Applies to