multiple file streams on the same file

Hello,

is it possible to have a file stream for writing and one for reading a file? I thought this would be possible with FileShare.Read but I get an exception after having created the file (with my write stream) and trying to open it with my read stream.

It looks like this:

this.writeStream = new FileStream(this.dataUri, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
this.readStream = new FileStream(this.dataUri, FileMode.Open, FileAccess.Read, FileShare.Read);

And I'm getting the following exception at the 2nd line:

The process cannot access the file '<filename>' because it is being used by another process.

Can anyone help?

[672 byte] By [ctusch] at [2008-1-10]
# 1
Looks like you have to use FileShare.ReadWrite in both places. Not sure why...
MatthewWatson at 2007-10-3 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
Tried it - works. Thanks! I already tried to set the 1st stream's share to ReadWrite but that didn't work and I didn't try it with the reading stream.. seems to be some kind of bug. Anyway, thanks!
ctusch at 2007-10-3 > top of Msdn Tech,Visual C#,Visual C# General...