Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileStream with locked file

I am wondering if it's possible to get a readonly FileStream to a locked file? I now get an exception when I try to read the locked file.

using (FileStream stream = new FileStream("path", FileMode.Open))

Thanks!

like image 735
SaphuA Avatar asked May 17 '11 18:05

SaphuA


People also ask

How do I unlock a .lock file?

Right-click on the file. In the menu that appears, select Lock File. To unlock, right-click the file and select Unlock File.


1 Answers

You should try another constructor. They are documented at MSDN.

This one looks like a bet:

FileStream Constructor (String, FileMode, FileAccess, FileShare)

MSDN Link

FileAccess

A constant that determines how the file can be accessed by the FileStream object. This gets the CanRead and CanWrite properties of the FileStream object. CanSeek is true if path specifies a disk file.

FileShare

A constant that determines how the file will be shared by processes.

like image 100
jgauffin Avatar answered Sep 22 '22 21:09

jgauffin