G
Guest
Sorry for aksing such a basic question but I have searched the internet high
and low and none of the solutions seem to help.
Here is my (not working) code:
FileStream fs = new FileStream(FileName, FileMode.Open,
FileAccess.ReadWrite, FileShare.None);
fs.lock(0, fs.Length);
So as you can see I am trying three different techniques at once:
* Opening the file with write access in the hope that this automatically
prevents other applications from opening the file with write access.
* Opening with FileShare.None in the hope that it would prevent the file
from being shared with other applications.
* Explicitly locking the file using the Lock method.
However, it doesn't work, other applications can still do anything they want
with the file including writing to it, renaming or moving it or deleting it.
Here is the task I want to do: On a server there are a whole bunch of files
that need to be manually annotated. To speed the process several people can
work on the files. Obviously I don't want two people to work on the same file
so some sort of locking mechanism is in order.
I also thought of another solution: Move the file from the sever to a local
directory and work on it there. However this does have the disadvantage that
if something goes wrong the file is no longer visible for the others. One
would have to make sure that such cases are caught and the file moved back to
the server.
Does anyboday have ideas?
Thanks in advance for any help!
Marcus
and low and none of the solutions seem to help.
Here is my (not working) code:
FileStream fs = new FileStream(FileName, FileMode.Open,
FileAccess.ReadWrite, FileShare.None);
fs.lock(0, fs.Length);
So as you can see I am trying three different techniques at once:
* Opening the file with write access in the hope that this automatically
prevents other applications from opening the file with write access.
* Opening with FileShare.None in the hope that it would prevent the file
from being shared with other applications.
* Explicitly locking the file using the Lock method.
However, it doesn't work, other applications can still do anything they want
with the file including writing to it, renaming or moving it or deleting it.
Here is the task I want to do: On a server there are a whole bunch of files
that need to be manually annotated. To speed the process several people can
work on the files. Obviously I don't want two people to work on the same file
so some sort of locking mechanism is in order.
I also thought of another solution: Move the file from the sever to a local
directory and work on it there. However this does have the disadvantage that
if something goes wrong the file is no longer visible for the others. One
would have to make sure that such cases are caught and the file moved back to
the server.
Does anyboday have ideas?
Thanks in advance for any help!
Marcus