Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. deleting in use files

deleting in use files

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hassan azizi
    wrote on last edited by
    #1

    how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006

    D C D 3 Replies Last reply
    0
    • H hassan azizi

      how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • H hassan azizi

        how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006

        C Offline
        C Offline
        CodyGen
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • H hassan azizi

          how i can delete in use files in my program using IO.File class? -- modified at 9:59 Sunday 15th January, 2006

          D Offline
          D Offline
          Daniel Grunwald
          wrote on last edited by
          #4

          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); }

          1 Reply Last reply
          0
          • C CodyGen

            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.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups