Hello,
I have a Text file that a product writes its logs on it, i want to build an application that writes the new logs on database, so i want my application to open this file for read always, the problem is that an exception would fires if the product tries to write on it because it is opened for read, how could i solve that?
Read and write on text file
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Pravin Patil60 reputationPosted Sep 14, 2012, 7:36 AM EDT
FileStream stream = new FileStream(@"FileName", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
When you are opening a file for Reading only, then you should open it in Read accese mode -
FileStream stream = new FileStream(@"FileName", FileMode.Open, FileAccess.ReadWrite, FileShare.Read)
Hope this helps.
All the best.