question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't Access Raw Asset Path

See original GitHub issue

Say I have an asset called livefree.ogg that is located in Raw/Songs

Application
  |-Resources
    |-Raw
      |-Songs
        |-livefree.ogg -> Build Action: Maui Asset

If I need to say, loop over all the files in Raw/Songs, how do I do so? Using FileSystem.OpenAppPackageFileAsync doesn’t get me access to the path of the item, just a stream. Which in my case, I need a path and not a stream. Is this possible with MAUI?

None of the following return any files:

Directory.GetFiles("Songs"); 
Directory.GetFiles("/Songs"); 
Directory.GetFiles("Resources/Songs");
Directory.GetFiles("/Resources/Songs");
Directory.GetFiles("Raw/Songs");
Directory.GetFiles("/Raw/Songs"); 
Directory.GetFiles("Resources/Raw/Songs"); 
Directory.GetFiles("/Resources/Raw/Songs"); 
Directory.GetFiles(Path.Combine(FileSystem.AppDataDirectory, "Songs")); 
Directory.GetFiles(Path.Combine(FileSystem.AppDataDirectory, "Raw", "Songs"));
Directory.GetFiles(Path.Combine(FileSystem.AppDataDirectory, "Resource", "Raw", "Songs"));

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
BinaryAssaultcommented, Jun 12, 2022

@xtuzy, so you’re saying the only possible way would be to copy all resources to the apps local data folder, then accessing them that way? I personally don’t like this as it would double the size of the resources.

It seems like the chosen answer on the stackoverflow link shows a function for Android assembly.GetManifestResourceNames which returns the paths of all resources. Isn’t that what you needed?

That particular function is related to C# reflection and not specific to Android. It can work if you set the build action to ‘Embedded Resource’ instead of a ‘MauiAsset’.

Although a workaround, it would be nice to have direct access to MauiAssets. I’m going to guess there is some lower level OS limitations with direct access and maybe that is why it isn’t available.

1reaction
BinaryAssaultcommented, Jun 12, 2022

@xtuzy, so you’re saying the only possible way would be to copy all resources to the apps local data folder, then accessing them that way? I personally don’t like this as it would double the size of the resources.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get access to raw resources that I put in res folder?
For raw files, you should consider creating a raw folder inside res directory and then call getResources().
Read more >
Resource Raw Folder in Android Studio
In Android one can store the raw asset file like JSON, Text, mp3, HTML, ... Step 1: To create the Resource Raw folder...
Read more >
Assets or Resource Raw folder of Android? | by Elye
Compile-time checking: res/raw is possible. assets folder. Here, the way you read it into InputStream is assets.open("filename").
Read more >
Assets Folder in Android Studio
If one wants to access data untouched, Assets are one way to do it. ... In Android one can store the raw asset...
Read more >
File system helpers - .NET MAUI
NET MAUI projects will process any file in the Resources\Raw folder as a MauiAsset. The FileSystem.OpenPackageFileAsync method can't get the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found