Results 1 to 4 of 4

Thread: How Do I Open A File For Read Only That Is Locked

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    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?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Re: How Do I Open A File For Read Only That Is Locked

    no bodys knows ??

  3. #3
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    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
  •  



Click Here to Expand Forum to Full Width