By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Help needed with deleting a file.... Error: File is being used by anohter process.

P: 4
I want to display a saved picture in a picture box, then delete the file, but i get the error:
"The process cannot access the file "C:\IMAGES\ABCDEF.jpg" because it is being used by another process."

here is the code i'm using.

PicBox.Image = Image.FromFile(C:\IMAGES\ABCDEF.jpg")
PicBox.Image.Dispose()
PicBox.Image = Nothing

File.Delete(C:\IMAGES\ABCDEF.jpg") 'ERROR HERE

'Also tried:
Kill(C:\IMAGES\ABCDEF.jpg") 'ERROR HERE

_______________________________

How can i release this file so I can delete it?
Jan 24 '08 #1
Share this Question
Share on Google+
4 Replies


daniel aristidou
100+
P: 491
If you are using vb08 there is a process controller....i've never tried it but it may allow you to terminate the process.
I 'm not sure about other vb versions
Jan 24 '08 #2

P: 4
For reference I am using VB.Net 2003.
Jan 25 '08 #3

P: 1
Use FileStream and make a clone of that image, then load the image into picturebox.

FileStream fStream = new FileStream(strImageURL, FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(fStream);
picBoxImage.Image = (Image)img.Clone();
img.Dispose();
fStream.Flush();
fStream.Close();
Jul 2 '10 #4

Expert 5K+
P: 8,434
@leojmagno
Don't know whether you noticed, Leo, but the post was over two years old. So the original poster may not get much out of the response.

However, while some people may bag you for responding to such an old post, it should be kept in mind that this answer is now available to anyone else who comes searching for help with the same problem. So, bravo!
Jul 17 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.