I need to be able to read from a file that's also open for writing, and furthermore, I need to open the writable file for Append, because it can be very large and I only need to add to it. So I have this code:
var file = @"...";
var fsWrite = new FileStream(file, FileMode.Append, FileAccess.ReadWrite, FileShare.ReadWrite);
var writer = new SmartWaveFileWriter(fsWrite, WaveInfo.WatsonWaveFormat);
var fsRead = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
var reader = new SmartWaveFileReader(fsRead);
reader.Dispose();
fsRead.Dispose();
writer.Dispose();
fsWrite.Dispose();
This fails with System.ArgumentException: Append access can be requested only in write-only mode.
If instead of FileMode.Append, I use FileMode.OpenOrCreate, I get no errors, but the contents of the file are lost.
How can I accomplish append but also be able to open the file for sharing like this?