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
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