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. setting folder/file access after creation

setting folder/file access after creation

Scheduled Pinned Locked Moved C#
helpquestion
4 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.
  • M Offline
    M Offline
    marky777
    wrote on last edited by
    #1

    hi. I am creating a folder and writing files to it in code. After the file is created, it emails it. After emailing i want to delete it off the sever's disk. I get the following error after i create the file The process cannot access the file 'C:\\pdfConversion\\SpiderSearchReport_DAY COLIN ANTHONY.PDF' because it is being used by another process." I am not using response object to write the file. The file is closed after creation. Can anyone help me to set the file 2 be able to be deleted after? Thanks.

    C 1 Reply Last reply
    0
    • M marky777

      hi. I am creating a folder and writing files to it in code. After the file is created, it emails it. After emailing i want to delete it off the sever's disk. I get the following error after i create the file The process cannot access the file 'C:\\pdfConversion\\SpiderSearchReport_DAY COLIN ANTHONY.PDF' because it is being used by another process." I am not using response object to write the file. The file is closed after creation. Can anyone help me to set the file 2 be able to be deleted after? Thanks.

      C Offline
      C Offline
      CKnig
      wrote on last edited by
      #2

      My guess is that your own process still has the file handle opened. So make sure that you close the File(Stream?). Best practice is to surround the FileStream with an using(...){} - so you make sure that Dispose is called and the handle is freed. If you forget this you will have to wait till the GC kicks in and frees the object for you (or till you close the process)

      M 2 Replies Last reply
      0
      • C CKnig

        My guess is that your own process still has the file handle opened. So make sure that you close the File(Stream?). Best practice is to surround the FileStream with an using(...){} - so you make sure that Dispose is called and the handle is freed. If you forget this you will have to wait till the GC kicks in and frees the object for you (or till you close the process)

        M Offline
        M Offline
        marky777
        wrote on last edited by
        #3

        thanks, i'll try that.

        1 Reply Last reply
        0
        • C CKnig

          My guess is that your own process still has the file handle opened. So make sure that you close the File(Stream?). Best practice is to surround the FileStream with an using(...){} - so you make sure that Dispose is called and the handle is freed. If you forget this you will have to wait till the GC kicks in and frees the object for you (or till you close the process)

          M Offline
          M Offline
          marky777
          wrote on last edited by
          #4

          I found out it might be my email sending code that locks the file until it sends it successfully. How can i check if an email has been sent successfully or not?

          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