I am wondering if it\'s possible to get a readonly FileStream to a locked file? I now get an exception when I try to read the locked file.
using (FileStream
using (FileStream stream = new FileStream("path", FileMode.Open))
That will use the default value for the FileShare argument, FileShare.Read. Which denies any process from writing to the file. That cannot work if another process is writing to the file, you cannot deny a right that was already gained.
You have to specify FileShare.ReadWrite. That might still not work if the other process used FileShare.None, no workaround for that. Beware that getting read access to a file that's being written is troublesome, you don't have a reliable end-of-file indication. The last record or line in the file might have only been partially written.