Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP: File.ReadAllBytes from file in Assets folder

How can I use File.ReadAllBytes()to read a file from the Assets folder into a byte[]? Therefore I need a filepath. I tried with ms-appx-web:///Assets/test.jpg, but that didn't worked. File.Exists() return false.

How do I get the absolute path to the assets folder?

like image 732
testing Avatar asked Mar 16 '16 11:03

testing


1 Answers

This fragment shoud do,

string fname = @"Assets\test.jpg";
StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await InstallationFolder.GetFileAsync(fname);
if(File.Exists(file.Path))
{
    var contents = File.ReadAllBytes(file.Path);
}
like image 143
Soundararajan Avatar answered Sep 17 '22 20:09

Soundararajan