7

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?

1 Answer 1

16

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);
}
1
  • Will the file be read two times? How can File.Exists() be used in this case?
    – testing
    Mar 16, 2016 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.