How to delete a file which is in use/open by some process in runtime. I am using vb.net for my project and a image is shown in picturebox, and that should be deleted, without cl
If the file is opened by another process in exclusive mode, you can't -- Windows won't let you. In that case, the best you can do is to either wait for the other process to close the file and then delete it, or have it be deleted at the next reboot by using MoveFileEx() with the flag MOVEFILE_DELAY_UNTIL_REBOOT
and a destination location of NULL
.
If the file is opened non-exclusively by another process, you can just call DeleteFile() normally (assuming you have permission to do so). The file will remain while the other process has it open, but it will be deleted as soon as the other process closes it.
(And yes, I realize those links are for the Win32 C API; the same functions should be available under VB .NET)