cannot delete file from server
hi every one.
I've run into a bit of a problem, i have looked o the net but I havent come up with a solution yet
we upload the file, save it as a temp file on server , read data from it, update the database and close the filestream and then try to delete it but sometimes, it gives this weird error that its still in use... when debugging through the code 'slowwly' this error is not encountered but even going fast in debugging mode this eception occurs again, here's the code
///
...
fileStream.DiscardBufferedData()
fileStream.Close()
fileStream = Nothing
binddgErrors()
If Not errorIndicator Then displayRecordCount(validRecordCount, invalidRecordCount, duplicateRecordCount)
initDeleteOperation()
...
///
Private Sub initDeleteOperation()
If Not File1.PostedFile Is Nothing Then
If CheckFileType() Then
If File1.PostedFile.ContentType = "text/plain" Then
If File.Exists(Server.MapPath("UploadedFile\" & Session.SessionID & ".txt")) Then DeleteFile(("UploadedFile\" & Session.SessionID & ".txt"))
Else
If File.Exists(Server.MapPath("UploadedFile\" & Session.SessionID & ".xls")) Then DeleteFile(("UploadedFile\" & Session.SessionID & ".xls"))
End If
End If
End If
End Sub
Private Sub DeleteFile(ByVal filename As String)
Dim f As File
f.Delete(Server.MapPath(filename))
End Sub
I even tried have the buffer flushed and assigning teh reference to null, still it says that the file is in use on the delete method....
anyone knows a work around? (sure I could look up any text files in the folder at the start of the procedure and delete them, but I still want to know how to do it this way)
thanx
|