File Sharing / access

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
 
T

tomb

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

Tom
 
D

Denis Correard

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?
 
A

Andrew Morton

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
 

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