HOW TO: Read From a Locked Text File
Q: I'm trying to read a txt file using StreamReader, but the file is locked by another process. The problem is that, since this is a log file I can't stop the other process that is using it.
Even if one makes sure to specify the proper FileAccess and FileShare modes when opening the file she won't be able to read it if the other program has opened the file with an exclusive lock.
Since this is a very common problem I wanted to share a small but useful tip of how to do that:
Before you open the file simply copy it to ---> C:\Documents and Settings\<username>\Local Settings\Temp\. REASON: Avoids file access violations under Windows. Now open and read the copied file.
Saturday, January 26, 2008 11:12 PM