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:
Protected WithEvents fileGetImage As System.Web.UI.HtmlControls.HtmlInputFile if page.isPostback then fileGetImage.PostedFile.SaveAs("c:\imagename.jpg") fileGetImage.Dispose() fileGetImage = Nothing ' Call the garbage collection System.GC.Collect end if ' You can now delete the image System.IO.File.delete("c:\imagename.jpg")




Reply With Quote