Determine if file is busy?

  • Thread starter Thread starter George Yefchak
  • Start date Start date
G

George Yefchak

Hi,

What's the correct System.IO - or - whatever call to determine if an
existing file happens to be open for writing by another application?

Thanks,
--George

* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: (e-mail address removed)
* Web: www.yefchak.com
 
Hi George

Try this:
*****************************
'Get the file.

Dim fileObj As New
System.IO.Filestream(filetowrite,FileMode.OpenOrCreate,FileAccess.Write,File
Share.None)

If fileObj.CanWrite Then

Console.WriteLine("The specified file is already open and writable.",
path)

End If

fileObj.Close()
****************************

There is also a way using "VB.Net" to lock a file so that no other client
can read or write
to the file using the "System.IO.FileStream" object.

e.g. Dim fileObj As New
System.IO.Filestream(filetowrite,FileMode.OpenOrCreate,FileAccess.Write,File
Share.None)

Hope this helps.

Regards,
Anushi
 
I try to lock the file for exclusive use and got the error, when file is
opened for editing.
This is correct? I don't know, but working.
 
Back
Top