martin_d_bell
Member
- Joined
- Oct 8, 2004
- Messages
- 17
Hi all,
I am really struggling with this one!!
I need to let users delete a bitmap file from a location on a server and also delete a record relating to this bitmap from a database at the same time. Every time I click on the delete button it throws an exception message saying "The process cannot access the file "\\server\blah\blah\myfile.bmp" because it is being used by another process"
I think I need to close the process somehow but have no clue how to do this.
My code is shown below:
Try
If MessageBox.Show("Are you sure you want to Delete this document?" & vbLf & vbLf & "NOTE: If you click Yes you will not be able to retrieve this Document.", "Delete Document", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
strFileID = DsVerifyDoc1.tblListerDoc.Rows(0).Item(0)
If docVerified = 1 Then
If System.IO.File.Exists(strFileName) = True Then
Try
ILFrames.Dispose()
LVBResults.Items.Clear()
System.IO.File.OpenWrite(strFileName)
System.IO.File.Delete(strFileName)
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Else
Me.lblVerified.Text = "Sorry but the Document you are trying to delete does not exist"
End If
SqlDeleteCommand1.CommandText = "DELETE FROM tblListerDoc WHERE (ID = " & strFileID & ")"
SqlDeleteCommand1.Connection = SqlCDocSearch
DsVerifyDoc1.tblListerDoc.Rows(0).Delete()
SqlDAVerifyDoc.Update(DsVerifyDoc1.tblListerDoc)
DsVerifyDoc1.tblListerDoc.Clear()
Else
End If
LVBResults.Items.Clear()
End If
Catch ex As Exception
MsgBox("SQL ERROR: Please try again")
End Try
Any help would be appreciated as I am tearing my hair out over this one.
Martin
I am really struggling with this one!!
I need to let users delete a bitmap file from a location on a server and also delete a record relating to this bitmap from a database at the same time. Every time I click on the delete button it throws an exception message saying "The process cannot access the file "\\server\blah\blah\myfile.bmp" because it is being used by another process"
I think I need to close the process somehow but have no clue how to do this.
My code is shown below:
Try
If MessageBox.Show("Are you sure you want to Delete this document?" & vbLf & vbLf & "NOTE: If you click Yes you will not be able to retrieve this Document.", "Delete Document", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
strFileID = DsVerifyDoc1.tblListerDoc.Rows(0).Item(0)
If docVerified = 1 Then
If System.IO.File.Exists(strFileName) = True Then
Try
ILFrames.Dispose()
LVBResults.Items.Clear()
System.IO.File.OpenWrite(strFileName)
System.IO.File.Delete(strFileName)
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Else
Me.lblVerified.Text = "Sorry but the Document you are trying to delete does not exist"
End If
SqlDeleteCommand1.CommandText = "DELETE FROM tblListerDoc WHERE (ID = " & strFileID & ")"
SqlDeleteCommand1.Connection = SqlCDocSearch
DsVerifyDoc1.tblListerDoc.Rows(0).Delete()
SqlDAVerifyDoc.Update(DsVerifyDoc1.tblListerDoc)
DsVerifyDoc1.tblListerDoc.Clear()
Else
End If
LVBResults.Items.Clear()
End If
Catch ex As Exception
MsgBox("SQL ERROR: Please try again")
End Try
Any help would be appreciated as I am tearing my hair out over this one.
Martin