dotnet / dotnet/dotnet-api-docs

FileShare Enum descriptions are incorrect/misleading

Open
#10,572 1 comment 0 reactions 0 assignees View on GitHub
area-System.IO help wanted Pri3
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.