FileShare Enum

Peter Volz 1,295 Reputation points
2023-04-02T15:38:53.1+00:00

Hello,

My case is vb.net:

Using imp As New FileStream(LoadTextBox.Text, FileMode.Open, FileAccess.Read)

Using exp As New FileStream(SaveTextBox.Text, FileMode.Create, FileAccess.Write)

...

End Using

only above 2 constructures, anyhow, since I don't specify the FileShare Enum, what's the default behavior for each one? (.netfw 4.0)

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,010 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,736 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2023-04-02T15:50:52.85+00:00

    According to documentation, “it is opened sharing Read access (that is, requests to open the file for writing by this or another process will fail until the FileStream object has been closed, but read attempts will succeed)” [https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream.-ctor?view=netframework-4.0#system-io-filestream-ctor(system-string-system-io-filemode-system-io-fileaccess)].


1 additional answer

Sort by: Most helpful
  1. Dewayne Basnett 1,366 Reputation points
    2023-04-03T17:44:28.1333333+00:00

    From the Remarks here, https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream.-ctor?view=netframework-4.8.1#system-io-filestream-ctor(microsoft-win32-safehandles-safefilehandle-system-io-fileaccess) It says "FileShare.Read is the default for those FileStream constructors without a FileShare parameter."

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.