I am looking for a way to store image files in my local filesystem using the PCL Storage plugin in my core Project for Windows Phone
, Xamarin.Android
and Xamarin.iOS
.
However, the plugin does just provide methods for writing Text. Nothing about bytes.
Is there a way to save byte arrays?
How about something like this:
IFile file = await FileSystem.Current.GetFileFromPathAsync(fs.filepath);
byte[] buffer = new byte[100];
using (System.IO.Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
stream.Write(buffer, 0, 100);
}
Edit: Some code taken from http://pclstorage.codeplex.com/
IFile file = await folder.CreateFileAsync("myfile.abc", CreationCollisionOption.ReplaceExisting);
Once you've got the IFile object you should then be able to use this in the same way:
IFile file = await folder.CreateFileAsync("myfile.abc", CreationCollisionOption.ReplaceExisting);
byte[] buffer = new byte[100];
using (System.IO.Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
stream.Write(buffer, 0, 100);
}
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