nogood
nogood

Reputation: 1330

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!

Upvotes: 3

Views: 2387

Answers (1)

Liyun Zhang - MSFT
Liyun Zhang - MSFT

Reputation: 14639

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.

Upvotes: 4

Related Questions