I have a small utility that deletes files from folders using .NET's FileInfo.Delete() method. Basically, I can catch an IOException if the file is currently open. This works for all files except for image files (JPG, GIF, BMP, ect.). When these types of files are open, the program is still able to delete them without throwing any exception. Have you encountered this before? How would go about detecting that these types of files are open so that I can prevent the deletion.
Thanks, Minh
Whether or not you can delete a file while it is open depends more on the program in which the file is open than the file type. If the application for instance simply reads the file contents and then closes the file (as Notepad for instance), you will be able to delete the file while it is "open" (meaning that it is showing in Notepad). Excel on the other hand keeps the file open in a manner that you usually are not able even to copy it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With