Blazor webassembly get file access

Christian Steinmetz 0 Reputation points
2023-05-24T06:08:42.3733333+00:00

How can I access local file system with blazor webassembly?

Sorry that was a try using AI. But it was not functional :-(

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,577 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 65,131 Reputation points
    2023-05-24T15:45:01.1033333+00:00

    to access the file system in a web assembly, you use js interop and call the file api.

    https://developer.mozilla.org/en-US/docs/Web/API/File

    the main restriction is the code can only open a file with the <input type="file"> control, not by name. that is the use must select the file.

    you use the FileReader to read a selected file:

    https://developer.mozilla.org/en-US/docs/Web/API/FileReader

    the other restriction is passing js binary (blob) data to blazor code. you will need to convert the blob to base64 (readAsDataUrl).

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.