Click to See Complete Forum and Search --> : Wite and Read to same file ERROR ?


sharong
March 27th, 2005, 02:53 AM
I'm using StreamWriter to write to file and at the same time I'm using the StreamReader to read from the same file.
Doing that cause an exception when I'm trying to create the StreamReader when the file is already opened fro writing by the StreamWriter.

How can I write and read at the same time to the same file?

Thanks
Sahron

cilu
March 27th, 2005, 06:58 AM
You can use FileStream and FileAccess.ReadWrite access rights.

Something like:

FileStream s = new FileStream(name, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);

Can read more in MSDN.

sharong
March 29th, 2005, 05:33 AM
Thanks,

I changed my code as you sugested and it works OK.
:thumb: