Click or drag to resize
GDFileIOReadBufferAsync Method
Reads the contents of the specified file and returns a buffer.

Namespace:  GD
Assembly:  GD (in GD.dll) Version: 255.255.255.255
Syntax
public static IAsyncOperation<IBuffer> ReadBufferAsync(
	IGDStorageFile file
)

Parameters

file
Type: GDIGDStorageFile
The file to read.

Return Value

Type: IAsyncOperationIBuffer
When this method completes, it returns an object (type IBuffer) that represents the contents of the file.
Examples
The following example shows how to read contents of file from the SDK secure storage.
using GD;
...
try
{
    var file = await GDWindows.Instance.SecureFolder.GetFileAsync("foo.bar");
    if (file != null)
    {
        var buffer = await GDFileIO.ReadBufferAsync(file);

        // Use a dataReader object to read from the buffer
        using (var dataReader = DataReader.FromBuffer(buffer))
        {
            string fileContent = dataReader.ReadString(buffer.Length);
            // Perform additional tasks
        }
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}
See Also