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 a file in use

deleting a file in use

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.
  • O Offline
    O Offline
    Ofori Boadu
    wrote on last edited by
    #1

    I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?

    a novice

    B S L 3 Replies Last reply
    0
    • O Ofori Boadu

      I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?

      a novice

      B Offline
      B Offline
      benjymous
      wrote on last edited by
      #2

      It sounds like the actual issue is that you're not actually closing the file when you're done with it.

      -- Help me! I'm turning into a grapefruit! Buzzwords!

      O 1 Reply Last reply
      0
      • O Ofori Boadu

        I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?

        a novice

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        You probably are not closing the file you previously opened for writing. If you are using the StreamWriter to write the contents, make sure you call Dispose after you're done with it. Or wrap it in a "using" block like

        using (StreamWriter writer = new StreamWriter(...))
        {
        writer.blah();
        }

        Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

        1 Reply Last reply
        0
        • B benjymous

          It sounds like the actual issue is that you're not actually closing the file when you're done with it.

          -- Help me! I'm turning into a grapefruit! Buzzwords!

          O Offline
          O Offline
          Ofori Boadu
          wrote on last edited by
          #4

          yeah, what happens it I add other things like signature and name to the photo and same them as one image,I don't need to close the program after the process is complete. I have to be doing for a lot of photos.

          a novice

          1 Reply Last reply
          0
          • O Ofori Boadu

            I have developed an application that takes a photo. I have a fixed path that the photos are saved to. I am able to save just one and after that unless I restart the whole application I am not able to save to overwrite the file because it sees the file as being in use. Any idea how I can overwrite or delete file in use?

            a novice

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, there may be two issues: 1. Most ways to load an image keep the image file open as long as the Image object is not Disposed() off. The only exception I am aware of is when reading an image through Image.FromStream() Remedy: use FromStream() or make sure you call Dispose(). remark: I don't think it is sufficient to Dispose() of a PictureBox if it is the only thing refering to the Image that got loaded from your file. 2. When a file, any file, is freshly written chances are some other utility is investigating it, prohibiting you from immediately renaming, deleting or overwriting it; candidate utilities are abything that works in the background on new files, such as file system indexers, and ativirus tools. Remedy: retry a couple of times, 1 second apart. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


            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