Reputation: 7628
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.
Upvotes: 2
Views: 9500
Reputation: 5921
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);
}
Upvotes: 6
Reputation: 69372
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.
Upvotes: 6