"Adrian <" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
|
| "Michael Nemtsev" <ne*****@msn.comwrote in message
| news:C0**********************************@microsof t.com...
| Is there a simple way to find out
| (1.) when a file is in use,
| >
| Just try to open for writing and check if exception was thrown
| >
| (2.) and when any file in a directory is in use,
| so file access by another user can be blocked?
| >
| Exception will be arised
| >
| --
| WBR,
| Michael Nemtsev :: blog:
http://spaces.live.com/laflour
| >
| "At times one remains faithful to a cause only because its opponents do
| not
| cease to be insipid." (c) Friedrich Nietzsche
|
| The problem is that in one directory there are data files and files that
| contain all sorts of parameters, that are used by all sorts of shared
| methods. So just using a FileShare parameter of the data files per
| se won't do. The only thing I can think of conceptually, is ascertaining
| whether the directory is in use or not, and blocking use of the data
| files of it is. However, I am unable to conceive a method for doing that.
There is no such thing like "Directory in use". If you want shared access to
files in an application, you have to open the files for shared read or
read/write access. For files shared for read-only access, there is nothing
special to be done, for files opened in R/W access mode you need to
coordinate the write accesses across the process boundaries, one way to do
this is by using a global mutex. If you wan't finer grained write access
control, you will have to lock file regions using FileStream.Lock/Unlock.
Willy.