Results 1 to 4 of 4

Thread: Cannot delete a file (File being used by another process) * Resolved *

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375

    Cannot delete a file (File being used by another process) * Resolved *

    Hi, I have a web application that spits out the following error when I try and delete a file from a code-behind page.

    "The process cannot access the file c:\path\blah.jpg" because it is being used by another process"

    If I wait a little while and try agiain then I can successfully delete the file from the exact same page.

    I have declared everything referencing the file to nothing but I still can't delete the file without waiting a few minutes

    Help appreciated

    Cheers

    =============

    The following is a subset of the code that I was having problems with. It was fixed by adding in

    fileGetImage.Dispose()
    fileGetImage = Nothing
    System.GC.Collect

    HTH anyone who has a similiar problem
    Cheers
    MarkusJ

    VB Code:
    1. Protected WithEvents fileGetImage As System.Web.UI.HtmlControls.HtmlInputFile
    2.  
    3. if page.isPostback then
    4. fileGetImage.PostedFile.SaveAs("c:\imagename.jpg")
    5. fileGetImage.Dispose()
    6. fileGetImage = Nothing
    7. ' Call the garbage collection
    8. System.GC.Collect
    9. end if
    10.  
    11. ' You can now delete the image
    12. System.IO.File.delete("c:\imagename.jpg")
    Last edited by MarkusJ_NZ; Sep 16th, 2003 at 10:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width