asp.net core mvc 读取文件

IFormFileIEnumerable<IFormFile>

 

private IHostingEnvironment _environment;
public TestController(IOptions<MyOptions> optionsAccessor, IHostingEnvironment env)
{
_optionsAccessor = optionsAccessor;
_environment = env;
}

   
[HttpPost] public async Task<IActionResult> Upload(IFormFile file, bool notUsed = false) { if (file != null) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } return View(); } [HttpPost] public async Task<ActionResult> Upload() { string path = Path.Combine(_environment.WebRootPath, "uploads"); IFormFile file = Request.Form.Files["file"]; if (file != null) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } return View(); }

  

posted @ 2016-08-30 15:05  ‖风之殇‖  阅读(3320)  评论(0编辑  收藏  举报