Hi guys,
I was wondering how one might test if a File is Locked without resorting to a Try..Catch..Finally block. Im not sure if it can be done, but I was thinking that it *should* be doable? Using a T/C/F block we can do something like this:
Any thoughts on if/how this could be done without a T/C/F block? (On the other hand, this ran surprisingly fast, Im not sure why... So its not really *that* improtant, but I was curious if anyone had some other thoughts on this...)
Thanks in advance!
Mike
I was wondering how one might test if a File is Locked without resorting to a Try..Catch..Finally block. Im not sure if it can be done, but I was thinking that it *should* be doable? Using a T/C/F block we can do something like this:
Code:
Shared Function FileIsLocked(ByVal fileFullPathName As String) As Boolean
Dim isLocked As Boolean = False
Dim fileObj As System.IO.FileStream
Try
fileObj = New System.IO.FileStream( _
fileFullPathName, _
System.IO.FileMode.Open, _
System.IO.FileAccess.ReadWrite, _
System.IO.FileShare.None)
Catch
isLocked = True
Finally
If fileObj IsNot Nothing Then
fileObj.Close()
End If
End Try
Return isLocked
End Function
Thanks in advance!
Mike