Skip to content

FileShare Enum descriptions are incorrect/misleading #10572

Open
@BillArmstrong

Description

@BillArmstrong

Type of issue

Other (describe below)

Description

The enum values state/imply that the effect is applied on "subsequent opening of the file". This is not correct because the value can cause the current file open request to fail based on previously opened file handles.

For example, the FileShare.Read value states the following:

Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed.

In the code below, the second attempt to open the file will fail because it is specifying FileShare.Read and the previous file open request has Write access to the file.

using var fileStream1 = new FileStream("test.file", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
using var fileStream2 = new FileStream("test.file", FileMode.Open, FileAccess.Read, FileShare.Read);

Please update the documentation so that it is clear that the FileShare value applies to existing file handles as well as future attempts to open the file.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.io.fileshare?view=net-8.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.IO/FileShare.xml

Document Version Independent Id

3bd9dbb8-0a53-ad3f-cd5d-c18d47f7f1a1

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.IOhelp wantedGood for community contributors to help [up-for-grabs]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions