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. File deletion in C#

File deletion in C#

Scheduled Pinned Locked Moved C#
csharphelpquestion
3 Posts 2 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.
  • G Offline
    G Offline
    gubber
    wrote on last edited by
    #1

    Hi, I'm trying to manipulate files in a C# program, when I delete a file however I run in to problems. It seems the file isn't really deleted until my application exits. I've tried it through File.Delete() and FileInfo.Delete(), and it seems to make no difference. The problem comes when after I have deleted the file I rescan the folder using Directory.GetFiles() and the "deleted" file is still there, except I can't read it. Do I need to somehow flush my file deletion?? Thanks in advance.

    S 1 Reply Last reply
    0
    • G gubber

      Hi, I'm trying to manipulate files in a C# program, when I delete a file however I run in to problems. It seems the file isn't really deleted until my application exits. I've tried it through File.Delete() and FileInfo.Delete(), and it seems to make no difference. The problem comes when after I have deleted the file I rescan the folder using Directory.GetFiles() and the "deleted" file is still there, except I can't read it. Do I need to somehow flush my file deletion?? Thanks in advance.

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi Gubber, did you opened the file before? Maybe there is still an open stream or somthing like this on the file. Maybe you should try to dispose the stream before? Regards Sebastian

      G 1 Reply Last reply
      0
      • S SeMartens

        Hi Gubber, did you opened the file before? Maybe there is still an open stream or somthing like this on the file. Maybe you should try to dispose the stream before? Regards Sebastian

        G Offline
        G Offline
        gubber
        wrote on last edited by
        #3

        Thanks!! That was exactly it.. I had opened a stream and forgot to Dispose of it. Cheers!

        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