hello i m deleting a file but it is giving the error that "The process cannot access the file 'D:\MyDataBase\106.jpg' because it is being used by another process."

What I did was I created a picture box and the when the form loads the picture box image is referenced to that directory... then i closed the dialog for the picture box and wanted to delete it but the error pops out. Is there something that I should do on that dialog to somehow close the image first after viewing?

Recommended Answers

All 9 Replies

window still opened (i mean your program is not currently closed), so when you try to delete it error came out cause picture box still opened it. thats my guesting.

I know... that's why am asking how to close that image

I know... that's why am asking how to close that image

I'd have thought a reboot is the simplist way to got, then delete it, if that don't work, then you have it running some how, by a program that starts with windows.

lol hehe.. it think you got it wrong.. of course i can delete the image manually when after I close the program but that's not my intention... what i want is that after the user views the picture using my program, i placed an option where the user can delete the picture.. but the picture can't be deleted cause it says the file is used by another process and i know that THAT process the picture dialog box is using it.. that's why am asking HOW to close the image or that process so i can delete the picture using the File.DELETE() function

It all depends on when you are letting the user delete the file.
Even through the dialog is closed, does not mean it has been disposed by garbage collection.

To insure you no longer have the picture file handle open, before closing the dialog (or in the FormClosed event handler), set the picturebox image to null.

pictureBox1.Image = null;

This frees the handle, and allows you to perform the delete.

// Jerry
If this solved your problem, please mark this message as solved.

It all depends on when you are letting the user delete the file.
Even through the dialog is closed, does not mean it has been disposed by garbage collection.

To insure you no longer have the picture file handle open, before closing the dialog (or in the FormClosed event handler), set the picturebox image to null.

pictureBox1.Image = null;

This frees the handle, and allows you to perform the delete.

// Jerry
If this solved your problem, please mark this message as solved.

Nope.. it didn't work

Then you have something else wrong with your code. If you can provide some demo code that can reproduce your problem, I would be happy to look at it.

// Jerry

jerry code should have been perform you to delete image. provide your code...

Hi. I runned into that damn problem too. And after days of searching I finally found this software: Delete Long Path File Tool.

It's GREAT. You can find it here: www.deletelongfile.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.