---
title: "What does FileShare enum do in file operations?"  
description: "What does FileShare enum do in file operations?"  
author: "ICSM Computer"  
published: 2025-05-07  
updated: 2025-06-01  
canonical: https://www.mindstick.com/forum/161588/what-does-fileshare-enum-do-in-file-operations  
category: "c#"  
tags: ["c#", "file handling"]  
reading_time: 2 minutes  

---

# What does FileShare enum do in file operations?

What does `FileShare` [enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum) do in [file operations](https://www.mindstick.com/forum/157675/explain-the-file-attribute-and-the-file-operations-in-operating-systems)? with example

## Replies

### Reply by ICSM Computer

The `FileShare` enum in .NET specifies the level of access other `FileStream` objects have to a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) that is already open. It controls how multiple processes or threads can read, write, or delete a file simultaneously.

### Namespace

```cs
System.IO
```

### Used in

When opening a file, such as with `FileStream`, `File.Open`, etc.

### Common Syntax

```cs
FileStream fs = new FileStream("example.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
```

### `FileShare` Enum Values

| Value | Description |
| --- | --- |
| `None` | No other process can access the file while it's open. (Default behavior if not specified.) |
| `Read` | Allows other processes to read the file. |
| `Write` | Allows other processes to write to the file. |
| `ReadWrite` | Allows other processes to read from and write to the file. |
| `Delete` | Allows other processes to delete the file. |
| `Inheritable` | Allows the file handle to be inherited by child processes. *(Rarely used)* |

### Example Use Case

```cs
using (FileStream fs = new FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read))
{
    // You can read/write, and others can still read the file
}
```

### Why It Matters

If you try to open a file that another process has locked with `FileShare.None`, your code will throw an `IOException`. Choosing the appropriate `FileShare` value prevents this.


---

Original Source: https://www.mindstick.com/forum/161588/what-does-fileshare-enum-do-in-file-operations

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
