且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET 5 RC1 MVC中使用IFormFile保存上传的文件

更新时间:2023-02-14 14:55:44

我遵循了@garethb

I followed the link suggested by @garethb here and used the extension method as suggested. It works!

ASP.NET RC1解决方案:

要包含的命名空间

using Microsoft.AspNet.Http;

控制器动作

[HttpPost]
public IActionResult Create(TeamVM vm)
{
     FormFileExtensions.SaveAs(vm.UploadedLogo, "C:\pathTofile");
     return View();
}

该答案的信用转到@garethb.

Credit for this answer goes to @garethb.

ASP.NET RC2解决方案:

要包含的命名空间

using Microsoft.AspNetCore.Http;
using System.IO;

控制器动作

[HttpPost]
public IActionResult Create(TeamVM vm)
{
     // Make sure the path to the file exists
     vm.UploadedLogo.CopyTo(new FileStream("C:\pathTofile", FileMode.Create));
     return View();
}