简体   繁体   中英

How do I access a file path in Blazor?

I added a file to

wwwroot/assets

the file is called zip.csv

private const string fileName = "zip.csv";
private const string filePath = "/assets/";

In my method,

var strLines = File.ReadLines(filePath + fileName);

I am getting a crash (log below)

blazor.webassembly.js:1 System.IO.DirectoryNotFoundException: Could not find a part of the path "/assets/zip.csv".

I can navigate to http://localhost:5000/assets/zip.csv and download the file

Clientside Blazor is running in the same sandbox as javascript. To interact with the user's file system, use the HTML standard for accessing the file system, eg with this Blazor wrapper .

Maybe localStorage is sufficient ? Check this Blazor package to use it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM