Reading a file used by another process
Posted
by
Tophe
on Stack Overflow
See other posts from Stack Overflow
or by Tophe
Published on 2012-03-18T15:51:04Z
Indexed on
2012/03/18
18:03 UTC
Read the original article
Hit count: 267
c#
I know this has been up for discussion but I can't find an answer to my specific problem. I am monitoring a text file that is being written to by a server program. Every time the file is changed the content will be outputted to a window in my program.
The problem is of course, that I can't use the Streamreader on the file as it is being "used by another process". Also setting up a Filestream with ReadWrite won't do any good since I cannot control the process that is using the file.
However... You CAN open the file in notepad, so somehow it must be possible to access it even though the server is using it.
Is there a good way around this? Should I monitor the file, make a temp copy of it when it changes, read the temp copy and the delete the temp copy.
I need to get hold of the text in the file whenever the server changes it.
© Stack Overflow or respective owner