rahavtom Posted October 7, 2004 Posted October 7, 2004 Hello! I use VB.NET and I have a form which contain a picturebox control that I fill with a choosen image by: Me.picImage1.Image = FromFile("1.jpg") Then I have a different button which suppose to clear the picturebox control, and delete the file itself from the original windows directory. The problem is that the picturebox is being cleared, but the file can't be deleted. It seems that it's locked or something, and I'm able to delete it only after I close the running program. Does anyone know what can be done in order to delete the file during runtime? Thanks! Tom. Quote
sizer Posted October 7, 2004 Posted October 7, 2004 post some code where you implemented file deletation Quote Some people are wise and some are other-wise.
rahavtom Posted October 7, 2004 Author Posted October 7, 2004 post some code where you implemented file deletation This is the code I use to delete the file: system.IO.File.Delete("1.jpg") Quote
Simcoder Posted October 7, 2004 Posted October 7, 2004 This is the code I use to delete the file: system.IO.File.Delete("1.jpg") You need to put the path inside of the quotes. Example - System.IO.File.Delete("C:\Program Files\1.jpg") Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
rahavtom Posted October 7, 2004 Author Posted October 7, 2004 You need to put the path inside of the quotes. Example - System.IO.File.Delete("C:\Program Files\1.jpg") Sure, in my source I put the full path as needed. I have a long path that I create in runtime, such "c:\" & ApplicationPath & PictureNumber & ".jpg" I didn't write it here because it was too complicated, and I prefered writing more simple picture name as example. Is there any other reason for that? Quote
Simcoder Posted October 7, 2004 Posted October 7, 2004 Sure, in my source I put the full path as needed. I have a long path that I create in runtime, such "c:\" & ApplicationPath & PictureNumber & ".jpg" I didn't write it here because it was too complicated, and I prefered writing more simple picture name as example. Is there any other reason for that? Can you give me the error message that is being displayed when you try to delete the file? Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Simcoder Posted October 7, 2004 Posted October 7, 2004 One More Thing, Assuming Your Paths Are Correct, It Seems To Be That You Can't Delete The File Because It Is Still In Use By Another Process. You Should Release The File From Memory, One Simple Way To Achieve This Would Be To Type "GC.Collect" Right Before You Delete The Image. That Should Work. Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Administrators PlausiblyDamp Posted October 7, 2004 Administrators Posted October 7, 2004 http://www.xtremedotnettalk.com/showthread.php?t=83882&highlight=delete+picturebox may be worth a look, also try to avoid calling GC.Collect() if at all possible - it can adversely affect performance. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rahavtom Posted October 8, 2004 Author Posted October 8, 2004 http://www.xtremedotnettalk.com/showthread.php?t=83882&highlight=delete+picturebox may be worth a look' date=' also try to avoid calling GC.Collect() if at all possible - it can adversely affect performance.[/quote'] Well, the original error message I got was: The file can't be deleted because it is still in use by another process... I added the line: Me.picImage1.Image.Diapose before I delete the file, so my code looks like this: Me. picImage1.Image.Dispose Me. picImage1.Image = Nothing File.Delete("...") The 'Dispose' solved part of the problem, because I'm able to delete the file whenever I want, but only when I still at that form. When I cloe the form and open it again, and then try to delete the file, I get the same error message (still in use...). I tried the GC.Collect as well but it didn't work... Thanks, Tom. Quote
Simcoder Posted October 8, 2004 Posted October 8, 2004 Hello! Me.picImage1.Image = FromFile("1.jpg") Tom. I'm not sure, but go ahead and put this code in right before you put a picture into the image. That should always dispose of the last used image. Then try deleting the file again and see what happens. If Not picImage1.Image Is Nothing Then picImage1.Image.Dispose() End If Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.