dotnet-Snippets.com
Snippets: 61 | Registered User: 61 | Visitors online: 2
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Check if file is in use

Author: Tim Hartwig
Programming Language: VB.NET Rating:
not yet rated

Views: 14992

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"



Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
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 Function



Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)