【发布时间】:2020-10-18 07:21:37
【问题描述】:
我正在尝试获取 Blazor WebAssembly 项目中 wwwroot 文件夹内的静态文件列表。这是我迄今为止尝试过的:
string[] images = Directory.GetFiles(@"wwwroot\images", "*.jpg");
我收到此错误:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Could not find a part of the path '/wwwroot\images'.
System.IO.DirectoryNotFoundException:找不到路径“/wwwroot\images”的一部分。
我做错了什么?谢谢。
【问题讨论】:
-
不幸的是,没有。这仅适用于 Blazor Server - 我正在使用 Blazor WebAssembly。
-
我认为您不能在 Blazor WebAssembly 应用程序中运行此代码。我知道如果你想读取位于 wwwroot 文件夹中的 json 文件的内容,你应该使用 HTTP 调用。但是,我猜想,只能使用 JSInterop 来检索文件的名称。试试 JSInterop,也许你会成功。
标签: c# .net-core blazor blazor-webassembly wwwroot