c# - 从“file://A/”获取文件
问题描述
如何从与本地计算机相同的外部路径获取文件"file://A/B/C/D/"
我可以访问“file://”的路径但用户无权访问。现在我想从“file://A/B/C/D/”中读取一些文件并让用户下载。
我该怎么做?
(当前目录为“ https://localhost:44331/ ”)
public async Task<IActionResult> DownloadDocument(string berichtsnummer)
{
var constantPath = "file://A/B/C/D/";
using (FileStream fileStream = System.IO.File.OpenRead(constantPath))
{
MemoryStream memStream = new MemoryStream();
memStream.SetLength(fileStream.Length);
fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
return File(fileStream, "application/octet-stream");
}
}
当我单击下载链接时,我收到此错误:
“IOException:文件名、目录名或卷标的语法不正确:” [
路径“file://A/B/C/D/”的视图:
解决方案
本地文件路径不是“file://”。您可以使用本地文件路径正常读取文件
var path = "C:\\...";
然后将内容发送到客户端浏览器。
如果文件不在本地计算机上,唯一的方法是使用网络共享访问它。然后您可以使用 UNC 路径,例如
var path = @"\\Server\Path\...";
推荐阅读
- numpy - 使用 joblib 较慢的并行计算和写入共享 numpy 数组
- python - 如何结合两个函数输出一个正式的句子?
- python - Python,bybit - 订单不存在或取消太晚
- python - Keras 多元时间序列预测模型返回 NaN 作为 MAE 和损失
- javascript - 在我的项目中(随机报价生成器)。我无法对问题进行排序?
- javascript - 如何阻止兄弟组件重新渲染?
- kubernetes - k8s 如何关联 ReplicaSet 和 Pod?
- heroku - 与heroku中的日志流断开连接
- python - 在python中计算每五秒的平均值
- r - 使用 ff 包时出错 ff 中的错误(initdata = initdata,.. 写入错误)