I've got a simple document viewing program that lists a group of files in a folder (mostly PDF's) and when the user clicks on a file in the list it shows on a webbrowser object.
I want to put in a utility to delete the file but I keep getting an error message (only on the PDF files) that "the file is in use". I tried both the file.delete("filename") and my.computer.filesystem.deletefile("filename") and get the same result. I even tried disposing the webbrowser object before the attempt to delete the file and it still resulted in the "object in use" error.
Below is the code.
Me.wbDoc.Url = Nothing
Me.wbDoc.Dispose()
If Me.lstFiles.Items.Count > 0 Then
Dim filename As String = Me.lstFiles.SelectedItem
Try
My.Computer.FileSystem.DeleteFile(filename)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
loadfiles()
Else : End If
I want to put in a utility to delete the file but I keep getting an error message (only on the PDF files) that "the file is in use". I tried both the file.delete("filename") and my.computer.filesystem.deletefile("filename") and get the same result. I even tried disposing the webbrowser object before the attempt to delete the file and it still resulted in the "object in use" error.
Below is the code.
Me.wbDoc.Url = Nothing
Me.wbDoc.Dispose()
If Me.lstFiles.Items.Count > 0 Then
Dim filename As String = Me.lstFiles.SelectedItem
Try
My.Computer.FileSystem.DeleteFile(filename)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
loadfiles()
Else : End If