Question : FileSystemWatcher VB.Net How to check if File is opened by application

Hi Experts.

how can I check if File is opened by application in VB.Net?

Answer : FileSystemWatcher VB.Net How to check if File is opened by application

You can attempt to open the file in exlusive read/write mode.  If the file is opened by anything else, the attempt will fail:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
    Private Function IsFileInUse(ByVal fileName As String) As Boolean
        Try
            Dim fs As System.IO.FileStream
            fs = New FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
            fs.Close()
            Return False
        Catch ex As Exception
            Return True
        End Try
    End Function
Random Solutions  
 
programming4us programming4us