How Do I Open A File For Read Only That Is Locked
I need to open a txt file for read only while another program updates the txt file.
I have been copying the file with File.Copy() but the txtfile gets up to 5+ megs sometimes and the program becomes really slow.
I tried to use the following code....
FileStream fs = new FileStream(@"c:\results.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
but it gets this error because the txt file is open
The process cannot access the file 'c:\results.txt' because it is being used by another process.
Is there any way open the txt file for read only when it is locked by another process?
Re: How Do I Open A File For Read Only That Is Locked
Re: How Do I Open A File For Read Only That Is Locked
I dont think that there is any way other than the one you are using already. Try to open it, if it works fine, if not catch the thrown System.IO Exception copy the File, and open that one. Thats the only way I know! Sorry!
Re: How Do I Open A File For Read Only That Is Locked
Yeah I was already coping the file and then reading it that way but it make the program very slow. I bet assembler could read the file without windows permission but I think that might be beyond the scope of this project. Thanks for the reply though.