Blazor read directory

asp.net-core blazor

Question

How do you read a content directory into Blazor.

I tried

Path.Combine(Directory.GetCurrentDirectory(), "..", "_posts");

But this throws an error.

Uncaught (in promise) Error: System.IO.DirectoryNotFoundException: Could not find a part of the path '/_posts'.
1
1
3/21/2019 10:07:58 PM

Popular Answer

The answer depends on why you want to read the directory

  • If you want to interact with the user's file system, then you need to use the HTML standard for accessing the file system. A blazor wrapper is provided at https://github.com/Tewr/BlazorFileReader
  • If you want to retrieve files from your server, there are multiple approaches based on how you want to use it. You could set up an api, an mvc instance, or just serve static files. They'll all be relative to your server though, not the current directory.
  • If you want store data client-side, Flores made a good suggestion to use https://github.com/BlazorExtensions/Storage
1
3/23/2019 2:51:30 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow