|
-
Jan 11th, 2006, 01:52 AM
#1
Thread Starter
Lively Member
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?
-
Jan 12th, 2006, 09:26 PM
#2
Thread Starter
Lively Member
Re: How Do I Open A File For Read Only That Is Locked
-
Jan 13th, 2006, 03:16 AM
#3
Hyperactive Member
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!
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Jan 13th, 2006, 08:36 PM
#4
Thread Starter
Lively Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|