Following is a sample method to check if a file has exclusive access to open and read.If the file is being used by other process the function will return true.
|
[VB.NET CODE STARTS]
‘– Add reference to System.IO
Imports System.IO
‘—————————————————————
Private Function IsFileInUse(ByVal filePath As String) As Boolean Dim fs As System.IO.FileStream = Nothing Try fs = New FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None) Return False Catch ex As Exception Return True Finally If Not fs Is Nothing Then fs.Close() fs.Dispose() End If End Try End Function
[VB.NET CODE ENDS]
|