I want to test if a file is in use. The code as follows was provided and it works! The problem now is that if I want to open the text file via notepad my vb.net app which just checked if the file is in use holds retains possession over it. How do I test if the file is in use but not take possession of it either. Releasing the file immediately after testing if its in use also works for me. Ive also tried to insert FileClose(1) but to no avail?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
System.IO.File.Open("C:\test.txt", IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.None)
MsgBox("In Use")
Catch ex As Exception
MsgBox("Not in use")
End Try
End Sub
End Class