Note that there are some explanatory texts on larger screens.

plurals
  1. POC# File.Delete, file being used by another process
    primarykey
    data
    text
    <p>I have a problem when I'm trying to delete an image file. I always get an error that says: IOExeption was unhandled. Acces denied because the file is beining used by another process.</p> <p>I do'nt know what process that could be and how to solve it.</p> <pre>private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { Album album = GetAlbum(comboBox1.SelectedIndex); Photo photo = GetPhoto(comboBox1.SelectedIndex, comboBox3.SelectedIndex); txtPhotoPath.Text = Directory.GetCurrentDirectory() + "\\" + photo.SPath; lblExtention.Text = photo.SExtention; txtPhotoTitle.Text = photo.STitle; pctrbFoto.Image = Image.FromFile(foto.SPath).GetThumbnailImage(GetWitdth(photo.SPath, GetHeight(photo.SPath, 150)), GetfHeight(photo.SPath, 150), null, new IntPtr()); } private void btnChangePhoto_Click(object sender, EventArgs e) { Album album = GetAlbum(comboBox1.SelectedIndex); Photo photo = GetPhoto(comboBox1.SelectedIndex, comboBox3.SelectedIndex); File.Delete("Albums\\Images\\" + photo.STitle + foto.SExtention); photo.SExtention = lblExtention.Text; photo.STitle = txtPhotoTitel.Text; Photo.SPath = txtPath.Text; File.Copy(photo.SPath, "Albums\\Images\\" + photo.STitle + photo.SExtention); }</pre> <p>Thanks, Vinzcent</p> <hr> <p>Thanks to all for the help.</p> <p>I used this and it works very well now</p> <hr> <p>your process is the one that uses file , you need to set image to null use something like this :</p> <p>var img = Image.FromFile(foto.SPath).GetThumbnailImage(GetWitdth(photo.SPath, GetHeight(photo.SPath, 150)), GetfHeight(photo.SPath, 150), null, new IntPtr());</p> <p>pctrbFoto.Image = img;</p> <p>img = null;</p> <p>GC.Collect();</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload