Search code examples
windows-mobilewin-universal-appassetsfilepath

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?


Solution

  • 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);
    }