Tips and tricks for .NET using ASP and VB code.

Determine if a file is locked.

    Shared Function IsFileLocked(ByVal FullPathAndFileName As String) As Boolean

Dim IsLocked As Boolean = False
Dim LockTextFileStream As System.IO.FileStream = Nothing
Try
LockTextFileStream = New System.IO.FileStream(FullPathAndFileName, IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
Catch
IsLocked = True
Finally
If LockTextFileStream IsNot Nothing Then
LockTextFileStream.Close()
End If
End Try
Return IsLocked
End Function

No comments:

Post a Comment

Search This Blog