【问题标题】:uploading the file to the path specified in .netcore将文件上传到 .net core 中指定的路径
【发布时间】:2021-05-14 23:00:02
【问题描述】:

我将上传的文件保存在根目录下。如何将它添加到我指定的路径(@“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# asp.net-core file-upload asp.net-core-mvc


【解决方案1】:

我认为这应该可以工作。因此,文件将上传到 C 盘而不是 wwroot。

string SavePath = Path.Combine(Directory.GetCurrentDirectory(), (@"C:\", model.FormFile.FileName);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-05
    • 2019-10-21
    • 2023-04-07
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多