如何将内容目录读入 Blazor。
I tried
Path.Combine(Directory.GetCurrentDirectory(), "..", "_posts");
但这会引发错误。
Uncaught (in promise) Error: System.IO.DirectoryNotFoundException: Could not find a part of the path '/_posts'.
答案取决于你为什么要阅读该目录
- 如果你想与用户的文件系统进行交互,那么你需要使用HTML标准来访问文件系统。提供 Blazor 包装纸https://github.com/Tewr/BlazorFileReader https://github.com/Tewr/BlazorFileReader
- 如果您想从服务器检索文件,可以根据您的使用方式选择多种方法。您可以设置一个 api、一个 mvc 实例,或者只提供静态文件。不过,它们都与您的服务器相关,而不是当前目录。
- 如果你想在客户端存储数据,弗洛雷斯提出了一个很好的建议 https://stackoverflow.com/a/52283340/2436737 to use https://github.com/BlazorExtensions/Storage https://github.com/BlazorExtensions/Storage
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)