c# - 将文件上传到 .netcore 中指定的路径
问题描述
我将上传的文件保存在根目录下。如何将此添加到我指定的路径(@“C:\ UploadsFolder”)?
public JsonResult Test(FileModel model)
{
string SavePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img", model.FormFile.FileName);
using (var stream = new FileStream(SavePath, FileMode.Create))
{
model.FormFile.CopyTo(stream);
}
return Json("");
}
在 FileModel.cs 中
public class FileModel
{
public string Files { get; set; }
public IFormFile FormFile { get; set; }
}
解决方案
我认为这应该可以工作。因此,文件将上传到 C 驱动器而不是 wwroot。
string SavePath = Path.Combine(Directory.GetCurrentDirectory(), (@"C:\", model.FormFile.FileName);
推荐阅读
- javascript - 浏览器会忽略“Accept-Encoding”标头吗?
- android - 如何为我的两个主题创建颜色状态列表?
- python - 我正在尝试检测屏幕上的移动,但出现错误:ValueError: too many values to unpack (expected 4)
- python - 使用 Pandas 过滤数据框中多列的唯一匹配
- swiftui - SwiftUI @EnvironmentObejct 似乎无法更新值
- java - 一键保存drawable文件夹中的多张图片
- javascript - JavaScript 项目石头剪刀布---页面首次加载时控制台的问题
- android - Firebase App Distribution 和 Google play 安全签名
- flutter - 如何在 Flutter 中将列表视图中的项目从一个类添加到另一个类?
- javascript - 如何在不同的 .js 文件上跨反应应用程序共享变量?