Search code examples
blazorblazor-webassembly

where do blazor wasm file writes go?


as a fun experiment (expected a notsupported exception) I did this is App.razor

protected override async Task OnInitializedAsync() {
    

        string[] lines =
    {
        "First line", "Second line", "Third line" 
    };

    await File.WriteAllLinesAsync("WriteLines.txt", lines);

     string[] lines2 = System.IO.File.ReadAllLines(@"WriteLines.txt");
}

and it works fine. Where did the data go?


Solution

  • Blazor has access to a memory based filesystem (memfs). I can't find much info about it, it's somewhere on the border between Mono and Blazor.

    You can for instance do System.IO.Directory.GetFiles("/"); and see (only) the WriteLines.txt file you just created.

    Where did the data go?

    Somewhere in the memory of the Browser.