-6

Possible Duplicate:
Read file which is in use?

I have a such situation/question:

  1. One txt file opened at present time by some program. This program writes some log stuff into file.
  2. My C# program should open that file in read-only mode but access should be silent and should not block access to file.

What C# function(s) could help me?

Thanks in advance.

Community
  • 1
  • 1
HotTeaLover
  • 93
  • 1
  • 1
  • 7

2 Answers2

1

You just have to pass the appropriate parameters to the File.Open() method:

using (var stream = File.Open("path", 
   FileMode.Open, 
   FileAccess.Read, 
   FileShare.ReadWrite))
{
    // You can read, they (logger) can write
}
Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
0

The FileShare flag allows to open an opened file.

vandango
  • 567
  • 1
  • 4
  • 13