4

Is there ability to read file that is used by another process?

Thanks.

iburlakov
  • 4,164
  • 7
  • 38
  • 40

3 Answers3

7

If the process holds an exclusive lock on the file then no. If the process holds a shared lock, you can read it.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • 3
    if a process holds a hared lock, it's possibleto read file like this: using (var stream = new FileStream(@"d:\myfile.xls", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {...} – iburlakov Jul 21 '09 at 10:12
1

Depending on the files you want to access, have a look at Volume Shadow Copy.

Maltrap
  • 2,620
  • 1
  • 33
  • 32
0

It depends on how the other process opened the file (i.e., is it locked). Bear in mind that reading a file while it is being changed by another process may yield unexpected results.

Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159