Alert user trying to delete an open file.
When trying to delete a file that is open in another program, it gives me an error instead of giving me a warning simply telling me why it failed.
I can fix this issue.
This occurs because Files UWP tries to delete the file and when it fails, it shows the exception message in a ContentDialog. While we could simply change the message, it will still show the confirmation dialog before deleting if that is enabled. A simple way to check if a file in use is to read it in a stream. If the file can't be read we could assume that the file is open.
@Jaiganeshkumaran Why not just handle the exception thrown when the file is in use?
@Jaiganeshkumaran Why not just handle the exception thrown when the file is in use?
It depends on what you mean by open. Some apps like notepad and the photos app don't lock their file so you can successfully delete those even if it is open. For now I am just going to handle the thrown exception.