【发布时间】:2023-03-19 21:14:01
【问题描述】:
我正在尝试通过单击客户端页面上的按钮在 Web 服务器上创建一个新文件。
浏览器控制台仅显示“WASM:已创建文件”。但不显示有关文件操作的任何错误或警告。
/wwwroot 路径下也没有新文件。
Blazor 服务器以管理员身份在 localhost (Win10) 上运行。
Index.razor 内容;
@page "/"
<h1>Demo1</h1>
<button type="submit" @onclick="CreateFile.Run">Create A New File</button>
@code
{
public class CreateFile
{
public static void Run()
{
System.IO.File.WriteAllText("test.txt", "hello world");
System.IO.File.WriteAllText(@"C:\VS Code Projects\Demo1\Client\wwwroot\samplefile.txt", "content 123");
Console.WriteLine("File created.");
}
}
}
【问题讨论】:
-
你考虑过输出当前的工作文件夹吗?
-
@BugFinder 不,我没有。仅使用默认项目设置。
标签: c# asp.net-core client blazor system.io.file