<form action="/ScenicService/PostFile" method="post" enctype="multipart/form-data">
<input type="file" name="files" id="file1" /><input type="submit" value="submit" />
</form>
[HttpPost]
public async Task<ActionResult> PostFile(IList<IFormFile> files)
{
if(!ModelState.IsValid)
{
return Content("not valid");
}
foreach (var file in files)
{
var fileName = ContentDispositionHeaderValue
.Parse(file.ContentDisposition)
.FileName
.Trim('"');// FileName returns "fileName.ext"(with double quotes) in beta 3
if (fileName.EndsWith(".txt"))// Important for security if saving in webroot
{
}
var filePath = _hostingEnvironment.ApplicationBasePath + "\\wwwroot\\" + fileName;
await file.SaveAsAsync(filePath);
}
return Content("ok");
}