I am trying to use a StreamReader to read a file, but it is always in use by another process so I get this error:
The process cannot access the file
try the below code.
FileStream fileStr = File.Open(, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
fileStream = new StreamReader(fileStr);
I have tried it on Windows XP. If the file is already open in write mode by some other process & it has not specified sharing rights, you will still be able to open the file in read mode.
Disclaimer: It works, but then, I am not sure if you should use it in production code. I am not yet able to find any formal documentation that says it should work.