Determine if file is busy?

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
 
A

Anushi

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
 
L

LinasB

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top