Why is my following codes sometimes work, but sometimes it does't work?
private bool UploadFile(IFormFile ufile, string fname)
{
if (ufile.Length > 0)
{
string fullpath = Path.Combine(_env.WebRootPath, fname);
using (var fileStream = new FileStream(fullpath, FileMode.Create))
{
ufile.CopyToAsync(fileStream);
}
return true;
}
return false;
}
The code did managed to save the picture to a folder which I created under wwwroot
, but the picture is not appearing, and even in Visual Studio too.
Is there a way to solve it?
Thanks.
Even when I open up the file explorer of the folder that is storing the pictures, the picture is like is there but not showing any image.
WebRootPath
is thewwwroot
whileContentRootPath
would be the location you set as the IIS root for the application.