androidmauiblazor-webassemblywwwroot

Dotnet Maui Blazor App - How to access images in wwwroot from static classin android platform?


In Maui Blazor Android Platform App I need to access wwwroot folder or somewhere image files are stored as file.

On Windows :

string rootpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot");

and var logoPath = "/img/proxiwash_black.jpg"; works well.

When I switch to Android it gives error like specified file not found.

Please help. Thanks...


Solution

  • For the android platform, the static file will be packaged into the apk file. It will not be stored in any folder which user can see. So it will throw error about file not found.

    In addition, the file can only read on the android. And you can use the .net maui file system helpers to access it. Scuh as FileSystem.OpenAppPackageFileAsync("wwwroot/data.txt");

    For more information, you can refer to the official document about the Static assets limited to Razor components in the .net maui.