Click here to Skip to main content
Rate this: bad
good
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
Comments
Abhishek Pant at 29-Dec-12 5:49am
   
just right click and refresh :laugh:
bikramjeet.sm 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
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,034
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,129
3 Maciej Los 3,079
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2014
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