Click here to Skip to main content
11,718,589 members (57,725 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Windows
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 at 29-Dec-12 5:49am
just right click and refresh :laugh: at 29-Dec-12 5:52am
i want to do that by code not manually..
GeekBond at 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
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415

Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2015
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