Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: alan.wedge

Hi @alan.wedge.  That is a tricky subject, and probably depends on where the file is stored, and where the 'other' person may be in relation to you (as far as network/internet and such), who may have that file open.  There is a way to check the 'ReadOnly' attribute of a file, but that is not really a good indicator that someone else may have a file open, because it is independent.  I saw a fairly simple code once for checking this, but it is not 100% effective for all file types.  For instance, when checked against simple text files, it did not seem to work, but when checked against PDF files, it seemed to work as expected.  'Seemed' being the keyword.  Here is something you can play around with.

Sub Main
	Dim oFile As String = "C:\Temp\ABC.pdf"
	If FileIsOpen(oFile) Then
		MsgBox("File is open.", , "")
	Else
		MsgBox("File not open.", , "")
	End If
End Sub

Function FileIsOpen(sFullFileName As String) As Boolean
	If Not System.IO.File.Exists(sFullFileName) Then
		Logger.Debug("sFullFileName was not found, or does not exist.")
		Return False
	End If
	Dim FS As System.IO.FileStream = Nothing
	Try
		FS = System.IO.File.Open(sFullFileName, System.IO.FileMode.Open, _
		System.IO.FileAccess.Read, System.IO.FileShare.None)
		FS.Close
		FS.Dispose
		FS = Nothing
		Return False
	Catch
		Return True
	End Try
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)