|
-
Apr 14th, 2003, 09:09 PM
#1
Thread Starter
Hyperactive Member
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:
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")
Last edited by MarkusJ_NZ; Sep 16th, 2003 at 10:56 PM.
-
Sep 16th, 2003, 12:59 PM
#2
Lively Member
Same Problem
I have the exact same problem and haven't been able to find a solution. Did you resolve this issue?
-
Sep 16th, 2003, 03:00 PM
#3
PowerPoster
Maybe forcing a garbage collection would solve this. I have also came across this problem, but found ways around it. I never tried garbage collection though, so who knows.
http://msdn.microsoft.com/library/de...collection.asp
http://msdn.microsoft.com/library/de...collection.asp
If you get it working, please post back what works.
-
Sep 16th, 2003, 09:28 PM
#4
Lively Member
Resolved
I encountered this problem when I create a file and delete it soon after. If I create the file using File.Create() or FileInfo.Create() I get the error when I delete the file that is created. If I create the file using the following code, I don't get the error...
Code:
Dim fsUpdateFile As New FileStream(strFile, FileMode.OpenOrCreate)
fsUpdateFile.Flush()
fsUpdateFile.Close()
I don't know if it will help anyone else, but it seems to have solved my problems.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|