deleting in use files
-
how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006
-
how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006
You can't. It's as imple as that. The file must be closed, by every process that has it open, before you can delete it, move it, or rename it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006
-
how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006
Files in use cannot be deleted. But you can use this: [System.Runtime.InteropServices.DllImport("kernel32.dll")] private static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, int dwFlags); const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004; static void MarkFileToDeleteOnReboot(string fileName) { MoveFileEx(fileName, null, MOVEFILE_DELAY_UNTIL_REBOOT); }
-
I don't know for sure if there is a way using c#. I encounter same problem with deleting files that are currently in use. You can try using the force delete of vbscript if that is applicable. It works for me.
Not even that will force-delete a file that is locked open by any process. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome