0
I’m trying to get an image update on a criminal record. When I do this update I want to change the existing image to the new update image.
That’s why I’m using the File.Exists
and the File.Delete
where I check if an image already exists and if it exists I delete and replace it with the new image.
The problem is that it always returns me an exception and does not erase the existing image.
The exception is
The process cannot access the file 'C: xampp htdocs Iguanabarws app webroot img categorias 3.jpg' because it is being used by Another process.`
How can I solve 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;
}
How are you loading this image to Picturebox? You can put the code for this function in the question?
– Jéf Bueno
Probably you must be facing permission issues to the directory where the image is stored, try to do the same by accessing in another directory that is without access restrictions.
– Julio Borges
@I’m sorry to intrude, but it probably has nothing to do with this. His problem is that the image may be referenced in Picturebox
– Jéf Bueno
Opa @jbueno, no problem, we are here to help the community.
– Julio Borges
@jbueno to add the image to the Picturebox do so:
pictureBox1.Image = Image.FromFile(PATH_FOLDER + this.categoria.imagem);
– FernandoPaiva