I'm using ASPNETMAKER 2021 to create a custom page using dropzone.js to upload multiple files to a server folder. However, I need to add the dll references in the ewcontroller.cs file to solve the problem.
It is important to note that I have already tried to add it to the Nugets option and it had no effect. I'm having to add it directly to the file and run build.bat to make the project run without errors.
We are using the following code:
public async Task<IActionResult> UploadFiles(IFormFile filedata)
{
var files = HttpContext.Request.Form.Files;
if (files.Any())
{
foreach (var file in files)
{
if (file.Length > 0)
{
//Getting FileName
var fileName = Path.GetFileName(file.FileName);
//Assigning Unique Filename (Guid)
var myUniqueFileName = Convert.ToString(Guid.NewGuid().ToString("N"));
//Getting file Extension
var fileExtension = Path.GetExtension(fileName);
// concatenating FileName + FileExtension
var newFileName = String.Concat(myUniqueFileName, fileExtension);
await using var target = new MemoryStream();
await file.CopyToAsync(target);
var physicalPath = $"{new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "UploadedFiles")).Root}{$@"{fileName}"}";
string filePath = $"/UploadedFiles/{fileName}";
await using FileStream fs = System.IO.File.Create(physicalPath);
await file.CopyToAsync(fs);
fs.Flush();
}
}
return Json(new { status = true, Message = "Files Uploaded Successfully!" });
}
return View();
}
When compiling, the following error occurs:
ewcontroller.cs(407,40):error CS0103: The name "Path" does not exist in the current context
ewcontroller.cs(414,54):error CS0246: The type or namespace name "MemoryStream" cannot be found (missing a using directive or assembly reference?)
ewcontroller.cs(416,72):error CS0246: The type or namespace name "PhysicalFileProvider" cannot be found (are you missing an assembly reference?)
ewcontroller.cs(416,85):error CS0246: The type or namespace name "FileStream" cannot be found (missing a using directive or an assembly reference?)
Error: Failed to publish project.