Click to See Complete Forum and Search --> : Error deleting file.. please help!


mechtn
August 6th, 2002, 12:49 PM
An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll

Additional information: The process cannot access the file
"c:\Fax\524b2cfa00.tif" because it is being used by another process.


Tried..

File.Delete(curfax)
Kill(curfax)
oFileInfo = New System.IO.FileInfo(curfax)
oFileInfo.Delete()


i loaded the file into a picbox and then read the name of the file and path into a listbox. I'm setting the picbox to nothing, and deleting the file based on selected item.

this is my code for getting rid of it...

Dim movefax, curfax As String
Dim fi As New FileInfo(fswFaxWatcher.Path & "\" &
lstFaxes.SelectedItem.ToString)
curfax = fswFaxWatcher.Path & "\" & lstFaxes.SelectedItem
movefax = fswFaxWatcher.Path & "\Archive\" &
lstFaxes.SelectedItem
If File.Exists(movefax) Then
'MsgBox("Files Already Exists, Deleting Old File.",
MsgBoxStyle.Critical)
File.Delete(movefax)
End If
fi.CopyTo(movefax)
movefax = Nothing
lstFaxes.Items.Remove(lstFaxes.SelectedItem)
lstFaxes.ClearSelected()
picFax.Image = Nothing
picFax.Height = 0
picFax.Width = 0
If MessageBox.Show("Delete the selected files (files will be
permanently deleted)?", "Confirm Delete", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly) = DialogResult.OK Then
Dim delfile As System.IO.FileInfo
Try
delfile = New System.IO.FileInfo(curfax)

delfile.Delete()
Catch oops As Exception
MessageBox.Show("Error deleting file: " & oops.Message
& vbNewLine & oops.Source & oops.HelpLink, "Error")
End Try
End If
End Sub

please someone give me some advice, thanks..

marriealen
November 20th, 2010, 12:04 PM
I had the same problem,i tried everything but nothing worked except a small tool available at http:***********.com

DataMiser
November 21st, 2010, 01:30 AM
I ran into this a while back. I can't off the top of my head remember how I got past it. It has to do with the picture box not having released the object when you set it to nothing. If I do not forget I will take a look at my code tomorrow and see how I handled it.

DataMiser
November 21st, 2010, 02:47 PM
Looks like I am using an image object and then calling the dispose method of that object before I try to delete the file.
Dim MySourceImage As New Bitmap(PicFileName)
'processing code here
MySourceImage.Dispose()
System.IO.File.Delete(PicFileName)