VB.Net 2005:
Function FileInUse(ByVal FN As String) As Boolean
Try
Using fs As IO.FileStream = IO.File.Open(FN, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
Return False
End Using
Catch ex As IO.IOException
Return True
End Try
End Function
<= VB.NET 2003:
Function FileInUse(ByVal FN As String) As Boolean
Dim fs As IO.FileStream = Nothing
Try
fs = IO.File.Open(FN, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
Return False
Catch ex As IO.IOException
Return True
Finally
If Not fs Is Nothing Then
fs.Close()
End If
End Try
End Function
C