I'm trying to read from a *txt file that a program uses as a log. I haven't found any good articles on reading from logs using C#. so i created a streamreader object and i have it read from the log.txt
well, i want to read from the log while it's being updated by another program, so i have a file systemwatcher that triggers a change event, and that event tells the streamreader to go look at the file. but I keep getting an error from the streamreader that it can't access the file since it is open by another program.
what am i doing wrong? is the streamreader the wrong object to use?
How do i read a file open in another program?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Athian Miere5 pointsPosted Dec 17, 2005, 2:40 PM EST
using ( StreamReader reader = new StreamReader(new FileStream(fileName,
FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) )