local-storagemaui

Creating Hierarchical Folder Structure in .NET 8 MAUI for Storing Audio Files on Application level


I’m building a .NET 8 MAUI app where I need to organize audio files in a hierarchical folder structure. The use case is similar to a doctor taking audio notes for patients during visits.

Root
    +1001_John Dale
    -1002_Anna Simpson
     -2024-05-23
      09-12-45.wav
     -2024-05-21
      14-25-45.wav
      17-05-22.wav
    -1003_Johnatan Doe
     -2024-05-23
      09-32-45.wav
     -2024-05-20
      16-25-45.wav
  1. I want to create a folder and file structure/storage on application level like above on any platform supported by .NET MAUI. I would also want optionally to save/sync the same hierachy to Google Drive, Azure Blob Storage, or Amazon S3, so it would be nice to have some common interface that define saving this hierachy on either local or remote location (in the cloud).

  2. How can I achieve this hierarchical view in my .NET MAUI app? I want an expandable patient list where each patient’s folder expands to show visit dates and associated audio notes when the doctor exands a patient node by pressing + icon (or when searching for Patient_ID or Parts of Full_Name and only one record is found?

  3. Additionally, how do I load the folder and file structure from the root folder (without displaying the root folder itself)? Users should be able to configure the topmost folder in the app settings ("root" in this case).

Any guidance on defining the storage mechanism, implementing the hierarchical view, and loading the folder structure would be greatly appreciated!


Solution

  • To create folders and subfiles in MAUI, you can use FileSystem and System.IO to create them:

    public static void createFolder(string folderName)
    {
        string mainDir = FileSystem.Current.AppDataDirectory;
        string folderPath = Path.Combine(mainDir,folderName);
        if(!System.IO.Directory.Exists(folderPath))
        {
            System.IO.Directory.CreateDirectory(folderPath);
        }
    }
    

    Regarding reading the file contents, you can use FilePicker in MAUI.

    Since different platforms have different ways of accessing the file system, you need to perform corresponding operations based on the document content.