I'm trying to do an image update on a cadaster. When I do this update I want to change the existing image to the new update image.
For this I am using File.Exists
and File.Delete
where I check if an image already exists and if it is deleted and replaced by the new image.
The problem is that this always returns me an exception and does not delete the existing image.
The exception is
The process can not access the file 'C: \ xampp \ htdocs \ IguanaBarWS \ app \ webroot \ img \ categories \ 3.jpg' because it is being used by another process. '
How can I resolve this problem?
I'm trying like this.
private void saveImageCategoria(String imgName)
{
Image img = pictureBox1.Image;
Image imgResize = ResizeImage.getResizeImage(img, new Size(50,50));
if (File.Exists(PATH_FOLDER + imgName))
{
File.Delete(PATH_FOLDER + imgName);
}
imgResize.Save(PATH_FOLDER + imgName);
pictureBox1.Image = null;
}