I am updating the same image in ASP.NET Core MVC :
Here is my code:
public IActionResult UpdateProduct(IFormFile product_image, Product prd)
{
string ImagePath = Path.Combine(_env.WebRootPath,"ProductImages",product_image.FileName);
FileStream fs = new FileStream(ImagePath, FileMode.Create);
product_image.CopyTo(fs);
prd.product_image = product_image.FileName;
_manicontext.tbl_product.Update(prd);
_manicontext.SaveChanges();
return RedirectToAction("FetchProduct");
}
I am getting this error:
System.IO.IOException: ‘The process cannot access the file ‘red-kalenji-8771124.jpg’ because it is being used by another process.’
How to solve this error?
New contributor
Sarfaraz Qadir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.