gpt4 book ai didi

c# - 在 Blazor Server 中使用 InputFile 时如何获取完整文件路径?

转载 作者:行者123 更新时间:2023-12-03 08:18:30 38 4
gpt4 key购买 nike

我需要能够提取完整的文件名,包括用户使用我的 InputFile 元素选择文件时的路径。

因此,举个例子,使用这个

<InputFile OnChange="FileSelected" />

我可以像这样在事件处理程序中看到文件名

void FileSelected(InputFileChangeEventArgs eventArgs) {

//eventArgs.File.Name has just the name of the file, e.g. ABC.csv but I need the full path like c:\userfolder\ABC.csv

但经过各种谷歌搜索尝试后,我一直无法弄清楚如何获取完整的文件名。

这里的目的是向用户展示一个文件对话框,他们可以在其中选择一个文件,然后我可以使用完整文件路径加载所需的其他一些文件。

谢谢

最佳答案

then I could load a few other files that are needed using the full file path

不。

服务器无法读取客户端的文件系统。任何需要发送到服务器的文件,客户端都需要发送它们。

即使是客户端代码也受到浏览器沙盒环境的很大限制。用户需要提供该文件才能授予权限。请参阅:https://developer.mozilla.org/en-US/docs/Web/API/File

您可能需要重新考虑用例。因为浏览器明确不允许你做你想做的事情。

关于c# - 在 Blazor Server 中使用 InputFile 时如何获取完整文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68610230/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com