How to read files from wwwroot in Maui?

Viewed 86

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!

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.

Related