3

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!

nogood
  • 1,117
  • 1
  • 11
  • 34

1 Answers1

3

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.

Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • Yes I have found that approach in the .txt under -Resources-Raw-AboutAssets.txt. But I need a List of the FileNames that are in the Folder. Not the content of the file. – nogood Aug 21 '22 at 08:04
  • 2
    According to the [File system helpers](https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-system-helpers?tabs=windows) in the maui, the wwwroot folder is [bundled files](https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-system-helpers?tabs=windows#bundled-files), so it seems no api to get this folder as a directory and get the file list of it. You can report this to the github. @nogood – Liyun Zhang - MSFT Aug 22 '22 at 05:54
  • I found that an exception occurred when the first slash in wwwroot was present, so I needed to change it to `"wwwroot/audio"` – The Thirsty Ape Sep 05 '22 at 03:26