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?
Why did you do not use FileIO.WriteBytesAsync
method?
public static IAsyncAction WriteBytesAsync(IStorageFile file, System.Byte[] buffer);
You can do it in one line code:
await FileIO.WriteBytesAsync(storageFile, byteArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With