Question

Can someone tell me what permission and file share does OpenRead methods reads file with.

I am trying this code,

FileStream stream = File.OpenRead(FileName);

But being suggested to use this code,

var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);

So my question is, what File.OpenRead() uses by default if I don't provide other parameters.

I can't just change code as it's on production server.

Was it helpful?

Solution

From the documentation

[public static FileStream OpenRead(string path)] is equivalent to the FileStream(String, FileMode, FileAccess, FileShare) constructor overload with a FileMode value of Open, a FileAccess value of Read and a FileShare value of Read.

OTHER TIPS

You can see decompiling :

public static FileStream OpenRead(string path)
{
      return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
}

Which is the same as the second one :

public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
{
      return new FileStream(path, mode, access, share);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top