[VB.NET] การตรวจสอบว่าไฟล์ได้ถูกเปิดใช้งานอยู่หรือไม่
โค้ดขนาดเล็กๆนี้ ก็คงมีประโยชน์บ้างไม่มากก็น้อย สำหรับแอดมินเอามาแปะไว้กันลืมครับ 5555+Imports System.IO
' / --------------------------------------------------------------------------
' / Check File in use or open.
Public Function FileInUse(ByVal sFile As String) As Boolean
FileInUse = False
If System.IO.File.Exists(sFile) Then
Try
Using F As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
'// FileInUse = False
End Using
Catch
FileInUse = True
End Try
End If
End Function
หน้า:
[1]