Delete Picture File

LebenOjanen

New member
Joined
May 11, 2005
Messages
4
Programming Experience
5-10
I am making a program that allows users to enter information into a database and import pictures from other areas of their computer. The selected picture is copied to an Images directory inside the program directory.

However I cannot delete the image when the delete function is called. The error message I get says the image is still in use. I have tried the picturebox.Nothing, etc., commands and still recieve this error.

How can I delete the picture without having to close the form or put the pictures into some kind of delete-queue upon program exit?
 
Nada

Doesn't work. I still get the standard "Additional information: The process cannot access the file (Picture FIle Name Here) because it is being used by another process." Error

Any idea what could be causing this? So frusturating!
 
post the section(s) of code that "opens" the picture file & the section(s) of code that "deletes" the picture file
 
Code!

As requested here's the core Open and Delete parts of the code, from their respective functions.

Opening the Image:
VB.NET:
PreviewLoc=App_Path & "images\" & dr("RecipePicture")
PictureName = dr("RecipePicture")
picPreview.Image=System.Drawing.Bitmap.FromFile(PreviewLoc)

Ignore the wierd spacing in the above, not sure why the site is doing it, but PreviewLoc is one word.

Delete the Image:
VB.NET:
PicPreview.Image=Nothing
System.IO.File.Delete(App_Path & "images\" & TmpPicName)
 
actually it's easy to explain how he did that

he first checked to see if the picture still existed (of which it does) so then he disposes of the image (destroys it in memory) with this line: pictureBox1.Image.Dispose()

then set's the picture box to nothing and deletes the file
 
Back
Top