File Sharing / access

  • Thread starter Thread starter Denis Correard
  • Start date Start date
D

Denis Correard

Is there a way to find out if a file, say a TXT file, is already open by
another user/application in VB.net?

I tryed to look at "Stream", "FileInfo" but without success.

I need to know because in my app I move file from 1 place to another but if
the file is in use My app hangup without reporting an error.
I use:
Dim fi as new fileinfo(strfile)

fi.MoveTo(<<destination>>)

Can Anyone help?

Many thanks

Denis
 
I would try just opening the file first - if that doesn't work, then
don't try to move it.

Tom
 
Sound a good Idear but how would you go about opening a file without the
associated application like *.doc and word, PDF and adobe reader?
 
Denis said:
Sound a good Idear but how would you go about opening a file without
the associated application like *.doc and word, PDF and adobe reader?

You don't need to open the file in that sense, just to open it in the sense
that the OS is informed you want to do something with it.

From the help for Microsoft.VisualBasic.FileOpen:-

------------------------------------
This code example opens the file in Binary mode for reading; other processes
can't read file.

FileOpen(1, "TESTFILE", OpenMode.Binary, OpenAccess.Read, _
OpenShare.LockRead)
------------------------------------


So if you use that in a try..catch structure then you should get an
exception if your app can't get exclusive access to the file.

Andrew
 
Back
Top