ClientFileSystem
The ClientFileSystem 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.
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.
Retrieve Files
Getting a list of file handles from a given directory on the client file system.
// 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.
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.
// 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();
}