s

how to save IFormFile to disk edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 26 February 2021 | 3272

In asp .net mvc you could save System.Web.HttpPostedFile to a disk using HttpPostedFile's method SaveAs("filename.ext"). Check the code below on how to save IFormFile to disk.

Solution

IFormFileCollection files = HttpContext.Request.Form.Files;
IFormFile file = files[0];
using (Stream fileStream = new FileStream(Path.Combine(sPath   modifiedFileName), FileMode.Create))
{
  file.CopyTo(fileStream);
}