tags:

views:

30

answers:

2

I notice many applications like firefox allow me to watch part of a video (using VLC) when the file is still downloading. I would like to do that with my application. When i tried opening the video with VLC i get an error.

How do i allow reading when i write to a file? my open line is

File.Open(fn, FileMode.Append)

i do append so i can resume partial files.

+6  A: 

You should use the Open overload, that takes a FileShare parameter:

File.Open(fn, FileMode.Append, FileAccess.Write, FileShare.Read)

This way you explicitly state that other processes are allowed to open the file for reading while you are still writing to it.

driis
Thank you. (4 more to go..)
acidzombie24
+1  A: 

You are leaving it up to the Open() method to pick the FileShare value passed to the FileStream constructor. Which is FileShare.None. Specify your own.

Hans Passant