Cannot Delete File After File Upload (ASP.net 2.0)

L

LisaBigJax

I am utilizing the ASP.net FileUpload control to upload a file. After
upload, if a user tries to delete the file, I get the dreaded

The process cannot access the file
"D:\Inetpub\wwwroot\images\uploads\uploadedFile.jpg' because it is
being used by another process.

If I wait 15 seconds, the error will dissappear.

I did an extensive search on this error as it pertains to file uploads
and it seems the resolution is to close and/or dispose the file after
upload. I tried to do this with the Dispose() method after upload.

However, the error is still occuring ... any ideas? Code snippets are
below. (Using VWD,VB / 2.0)

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

Protected Sub btnUploadPic_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim fu As FileUpload = CType(DetailsView1.FindControl("FileUpload1"),
FileUpload)

checkForValidFile() // My own function to validate file

fu.SaveAs(pathPath)
fu.Dispose()

End Sub

Protected Sub btnDeleteFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
filePath = "d:/inetpub/wwwroot/images/uploads/fileJustUploaded.gif""
System.IO.File.Delete(filePath)
End Sub
 
R

Rajesh CKR

Are you storing any references in the validation function and not closing it
completely?

Try calling GC.Collect() after dispose and see if the error still occurs.

Also, if you are using any COM objects using CCWs, use
System.Runtime.InteropServices.Marshal.ReleaseComObject

Raj
 
L

LisaBigJax

No, I'm not using COM; I'm using the File Upload control that comes
standard with .NET 2.0 - Ill try yuor suggestion.
 
L

LisaBigJax

I am still getting this problem even after implementing the advice
above.

Anyone else? I can't seem to get this one figured out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top