UWP: byte[] to file

Viewed 3719

I have a byte[] and I want to store it into a file. This is my code:

using System.Runtime.InteropServices.WindowsRuntime;

StorageFolder folder = await GetStorageFolderFromFilePath(filePath);
StorageFile file = await folder.CreateFileAsync(Path.GetFileName(filePath), CreationCollisionOption.ReplaceExisting);

using (Stream stream = await file.OpenStreamForWriteAsync())
{
    IBuffer buffer = byteArray.AsBuffer();
    await FileIO.WriteBufferAsync(file, buffer);
}

A file is created but the file is empty. What am I doing wrong?

3 Answers
Related