Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read files from wwwroot in Maui?

In a maui blazor app I created the folder wwwroot/audio and put some files there. How can I get all the filenames from this directory?

        string mainDir = FileSystem.Current.AppDataDirectory;
        var audioFiles = Directory.GetFiles(Path.Combine(mainDir, "/wwwroot/audio"));

Didn't work!

like image 856
nogood Avatar asked Oct 25 '25 10:10

nogood


1 Answers

It seems you can't get the file directly. But you can get it by reading the file. Such as:

 using var stream = await FileSystem.OpenAppPackageFileAsync("wwwroot/audio");

I have done a sample to test and I can get the string in the txt file with a streamreader. If you need more information, please check the official document.

like image 186
Liyun Zhang - MSFT Avatar answered Oct 28 '25 03:10

Liyun Zhang - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!