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(); }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM