deleting a file in use
-
I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?
a novice
-
I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?
a novice
It sounds like the actual issue is that you're not actually closing the file when you're done with it.
-- Help me! I'm turning into a grapefruit! Buzzwords!
-
I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?
a novice
You probably are not closing the file you previously opened for writing. If you are using the
StreamWriter
to write the contents, make sure you callDispose
after you're done with it. Or wrap it in a "using" block likeusing (StreamWriter writer = new StreamWriter(...))
{
writer.blah();
}Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro
-
It sounds like the actual issue is that you're not actually closing the file when you're done with it.
-- Help me! I'm turning into a grapefruit! Buzzwords!
yeah, what happens it I add other things like signature and name to the photo and same them as one image,I don't need to close the program after the process is complete. I have to be doing for a lot of photos.
a novice
-
I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?
a novice
Hi, there may be two issues: 1. Most ways to load an image keep the image file open as long as the Image object is not Disposed() off. The only exception I am aware of is when reading an image through Image.FromStream() Remedy: use FromStream() or make sure you call Dispose(). remark: I don't think it is sufficient to Dispose() of a PictureBox if it is the only thing refering to the Image that got loaded from your file. 2. When a file, any file, is freshly written chances are some other utility is investigating it, prohibiting you from immediately renaming, deleting or overwriting it; candidate utilities are abything that works in the background on new files, such as file system indexers, and ativirus tools. Remedy: retry a couple of times, 1 second apart. :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.