May 1, 2010 09:05 PM
(This post was last modified: May 2, 2010 02:13 PM by codepoet.)
originally posted on dotnet-snippets.com
Description:
This function checks if a given file is in use by opening the file with exclusive read/write permissions. If the file is in use this function wont get exclusive permissions and will throw an exception and the function will return "true", otherwise you'll get "false"
If You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
Description:
This function checks if a given file is in use by opening the file with exclusive read/write permissions. If the file is in use this function wont get exclusive permissions and will throw an exception and the function will return "true", otherwise you'll get "false"
Code
Public Function FileInUse(ByVal sFile As String) As Boolean
If System.IO.File.Exists(sFile) Then
Try
Dim F As Short = FreeFile()
FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
FileClose(F)
Catch
Return True
End Try
End If
End FunctionIf You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
PHP & .NET Contributor.


