Language used: C#
Theory:
I want to create a file with the flag FileOptions.DeleteOnClose
in a temporary folder.
The file is successfully created and I write dato onto it, the next step is to launch the application associated with the file Process.Start(...)
and allow the user to inspect the document, finally I close my handle and as soon as other process close the handle to the temporary file, the file is deleted by operating system.
My problem is that other processes cannot open the file, even for reading, despite if I add FileShare.ReadWrite | FileShare.Delete
to the sharing mode.
Any suggestions?
Force delete using Windows With the command prompt open, enter del /f filename , where filename is the name of the file or files (you can specify multiple files using commas) you want to delete.
But don't worry, you can restart File Explorer again and get everything back. To close File Explorer, press Ctrl + Shift + ESC, find Windows Explorer, right-click the process, and select End task. Return to the Command Prompt. If you lost the window, press Alt + Tab to jump to it.
Locate the file that you want to delete. Right-click the file, then click Delete on the shortcut menu. Tip: You can also select more than one file to be deleted at the same time. Press and hold the CTRL key as you select multiple files to delete.
The other processes need to specify FileShare.Delete
when they open the DeleteOnClose
file
From the MSDN CreateFile docs:
"
FILE_FLAG_DELETE_ON_CLOSE
... Subsequent open requests for the file fail, unless theFILE_SHARE_DELETE
share mode is specified."
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