# ClientFileSystem

The [ClientFileSystem ](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API)extension allows interaction with files on a user's local device, or on a user-accessible network file system. Core functionality of this API includes reading files, writing or saving files, and access to directory structure.

{% embed url="<https://github.com/iceteagroup/wisej-extensions/tree/master/Wisej.Ext.ClientFileSystem>" %}
ClientFileSystem Source Code
{% endembed %}

## Features

* Write files on the client system.
* Read files on the client file system.
* Query files on the client file system.

## How to Use

The **ClientFileSystem** extension can be added to a Wisej.NET project using NuGet Package Manager.

{% embed url="<https://www.nuget.org/packages/Wisej-3-ClientFileSystem>" %}

### Retrieve Files

Getting a list of file handles from a given directory on the client file system.

```csharp
// get a directory from the client.
var directory = await ClientFileSystem.ShowDirectoryPickerAsync();
 
// get the files from that directory.
var fileHandles = await directory.GetFilesAsync("*.docx");
```

### Write File

Bytes or text can be written directly to a file on the client's file system.

```csharp
using (var fs = new FileStream(Application.MapPath("some/file.docx"), FileMode.Open)
{
    fileHandle.WriteBytesAsync(fs.ToArray(), 0, WritableType.Write, false);
}
```

### Read File

Bytes or text can be read directly from a file on the client's file system.

```csharp
// retrieve the first handle.
var fileHandle = files[0]; 	
 
// query read and write permissions on the file.
var state = await fileHandle.QueryPermissionAsync(Permission.ReadWrite);
if (state == PermissionState.Granted)
{
	// read and load the file.
	var bytes = await fileHandle.ReadBytesAsync();
}
```
