<form id="form1" method="post" action="/Home/Save">
<ejs-uploader id="fileupload" autoUpload="false" multiple="false" allowedExtensions="image/*"> </ejs-uploader>
<div class="submitBtn">
<button class="submit-btn e-btn" id="submit-btn" type="submit">Submit</button>
<div class="desc"><span>*This button is not a submit type and the form submit handled from externally.</span></div>
</div>
</form> |
public IActionResult Save(IList<IFormFile> fileupload)
{
try
{
foreach (var file in fileupload)
{
if (fileupload != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = hostingEnv.WebRootPath + $@"\{filename}";
if (!System.IO.File.Exists(filename))
{
//using (FileStream fs = System.IO.File.Create(filename))
//{
// file.CopyTo(fs);
// fs.Flush();
//}
}
else
{
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File already exists.";
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "No Content";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
}
return Content("");
} |