简体   繁体   English

如何访问 Blazor 中的文件路径?

[英]How do I access a file path in Blazor?

I added a file to我添加了一个文件

wwwroot/assets wwwroot/资产

the file is called zip.csv该文件名为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我可以导航到 http://localhost:5000/assets/zip.csv 并下载文件

Clientside Blazor is running in the same sandbox as javascript.客户端 Blazor 与 javascript 在同一个沙箱中运行。 To interact with the user's file system, use the HTML standard for accessing the file system, eg with this Blazor wrapper .要与用户的文件系统交互,请使用 HTML 标准来访问文件系统,例如使用此Blazor 包装器

Maybe localStorage is sufficient ?也许 localStorage 就足够了? Check this Blazor package to use it检查这个Blazor 包以使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Blazor 页面访问 env.IsDevelopment()? - How do I access env.IsDevelopment() from a Blazor page? 如何访问 Blazor RenderFragment 中的代码块? - How do I access the code block within a Blazor RenderFragment? 如何使用 Blazor 从 .CS 文件而不是 .RAZOR 文件访问在 Startup.cs 中注释的范围服务中的数据? - How do I access data within a scoped service, annotated in Startup.cs, from a .CS file NOT a .RAZOR file using Blazor? 如何将文件在线上传到文件夹而不会出现“对路径的访问被拒绝” - How Do I Upload a File To a Folder Online Without Getting "Access to the path is denied" 如何使用命令行参数中的文件路径在C#中打开访问数据库? - How do I open access database in C# using a file path from a command line argument? 如何在不使用绝对路径的C#中访问/打开文件? - How do I access/open a file in C# not using an absolute path? 如何在 Blazor 中访问浏览器 localStorage? - How can I access the browsers localStorage in Blazor? 如何从 blazor 中的 .cs 文件访问浏览器本地存储? - How do I access browser local storage from .cs files in blazor? 如何从 blazor(服务器端)Web 应用程序获取访问令牌? - How do I get the access token from a blazor (server-side) web app? 如何确保文件路径有效? - How do I ensure a file path is valid?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM