File handle

  • Thread starter Thread starter Stanley
  • Start date Start date
S

Stanley

I add some JPG files to a imagelist control and bind the imagelist to a
listview control.
This will list out all JPG files in the listview control.
Then I add a "Delete" button for deleting the JPG files.
In the click event of the "Delete" button, I remove the selecteditem from
the listview control and also the physical file.
I'm not able to delete the physical JPG file because an exception is thrown
and said that my program is still using the JPG file.
How to release the JPG file handle after accessing it using "image.fromfile"
?
Thanks.
 
Hi,

Open the image with image.fromstream instead. Image.fromfile locks
the file on the computer.

Dim fs As New System.IO.FileStream("C:\camera.bmp", IO.FileMode.Open)

Dim img As Image = Image.FromStream(fs)

fs.Close()

PictureBox1.Image = img



Ken

------------------------------
I add some JPG files to a imagelist control and bind the imagelist to a
listview control.
This will list out all JPG files in the listview control.
Then I add a "Delete" button for deleting the JPG files.
In the click event of the "Delete" button, I remove the selecteditem from
the listview control and also the physical file.
I'm not able to delete the physical JPG file because an exception is thrown
and said that my program is still using the JPG file.
How to release the JPG file handle after accessing it using "image.fromfile"
?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top