Click here to Skip to main content
13,551,686 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Friends,

I am developing a window application. I this app i am taking a photo via webcame and i save that image by code too. after save that Image i resized the image H and W. and also delete the old Image file from directory file path. the new Image reload in ImageBox of window .net control. but after save that Image file in data base i am again want to delete that image from that folder where i save for Temporary. i am also clear the image path like this I'm Using the Path to save image

"C:\\Users\\Public\\Pictures\\Sample Pictures\\"

pictureBox.ImageLocation =""

but i got a Exception which called path is in used you can able to delete this file
please help me how can i refresh the this path

"C:\\Users\\Public\\Pictures\\Sample Pictures\\"

to delete the file easily from this path..

Thank You
Posted 28-Dec-12 23:42pm
Abhishek_Pant 29-Dec-12 5:49am
just right click and refresh :laugh:
bikramjeetsm 29-Dec-12 5:52am
i want to do that by code not manually..
geekbond 29-Dec-12 6:35am
Refreshing won't solve your problem. You have to close (dispose) all handles of the file in your application before you can delete it.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It's not as simple as you may think to get rid of the "file in use" error - the problem is very often that the application that is using the file and preventing you from deleting it, is the application that is trying to do the delete.

And this is very often a problem with applications that copy images to other locations, or into databases.

The problem is that when you read the file data, if you do not properly close and dispose of all the streams, images and such like temporary data you load, it remains in use until the Garbage Collector decides it is not needed any more. This could be in an hours time, or next week!

Look at your loading code: check that everything that accesses the file is correctly Disposed, or enclosed in a using block.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180515.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100