FileSystemFileHandle Class

A handle to a file (https://fs.spec.whatwg.org/#api-filesystemfilehandle).

public sealed class FileSystemFileHandle : FileSystemHandle
Inheritance
FileSystemHandle FileSystemFileHandle

Properties

NameDescription
KindGets the kind of the entry.

Gets the kind of the entry.

public override FileSystemHandleKind Kind { get; }

Methods

NameDescription
CreateSyncAccessHandle()Creates an access handle that reads and writes the file in place, synchronously (https://fs.spec.whatwg.org/#dom-filesystemfilehandle-createsyncaccesshandle), in a dedicated worker. The access handle holds an exclusive lock on the file until it is closed. The task fails with a NotFoundError when the file does not exist, and with a NoModificationAllowedError when the lock cannot be taken.
CreateSyncAccessHandle(FileSystemCreateSyncAccessHandleOptions?)Creates an access handle with a locking mode: see FileSystemCreateSyncAccessHandleOptions.Mode.
CreateWritable(FileSystemCreateWritableOptions?)Creates a stream that writes the file (https://fs.spec.whatwg.org/#dom-filesystemfilehandle-createwritable): the writes go to a buffer, which replaces the content of the file when the stream is closed. The stream holds a lock on the file until it is closed or aborted. The task fails with a NotFoundError when the file does not exist, and with a NoModificationAllowedError when the lock cannot be taken (an access handle of the file is open).
GetFile()Returns a File with the current content of the file (https://fs.spec.whatwg.org/#dom-filesystemfilehandle-getfile): a snapshot, which the later writes do not change. The task fails with a NotFoundError when the file does not exist.
Move(FileSystemDirectoryHandle?, string?)Moves the file to another directory of the file system, with its name or with newName: see FileSystemFileHandle.Move.
Move(string)Renames the file (the move() method that the browsers implement for the files of the origin private file system; it is not in the File System Standard yet, see https://github.com/whatwg/fs/pull/10): the handle then locates the file at its new path. A file that has the new name is replaced. The task fails with a TypeErrorException for an invalid name, a NotFoundError when the file does not exist, and a NoModificationAllowedError while the file, or the file it replaces, is locked.

CreateSyncAccessHandle overloads

CreateSyncAccessHandle()

FileSystemFileHandle.cs

Creates an access handle that reads and writes the file in place, synchronously (https://fs.spec.whatwg.org/#dom-filesystemfilehandle-createsyncaccesshandle), in a dedicated worker. The access handle holds an exclusive lock on the file until it is closed. The task fails with a NotFoundError when the file does not exist, and with a NoModificationAllowedError when the lock cannot be taken.

public Task<FileSystemSyncAccessHandle> CreateSyncAccessHandle()

CreateSyncAccessHandle(FileSystemCreateSyncAccessHandleOptions?)

FileSystemFileHandle.cs
  • Experimental (WEBPLATEXP0007)

Creates an access handle with a locking mode: see FileSystemCreateSyncAccessHandleOptions.Mode.

[Experimental("WEBPLATEXP0007", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public Task<FileSystemSyncAccessHandle> CreateSyncAccessHandle(FileSystemCreateSyncAccessHandleOptions? options)

CreateWritable(FileSystemCreateWritableOptions?)

FileSystemFileHandle.cs

Creates a stream that writes the file (https://fs.spec.whatwg.org/#dom-filesystemfilehandle-createwritable): the writes go to a buffer, which replaces the content of the file when the stream is closed. The stream holds a lock on the file until it is closed or aborted. The task fails with a NotFoundError when the file does not exist, and with a NoModificationAllowedError when the lock cannot be taken (an access handle of the file is open).

public Task<FileSystemWritableFileStream> CreateWritable(FileSystemCreateWritableOptions? options = null)

Parameters

options FileSystemCreateWritableOptions?

Returns

Task<FileSystemWritableFileStream>

Remarks

In the scripts, the result is a FileSystemWritableFileStream, a WritableStream whose sink is the returned object.

Returns a File with the current content of the file (https://fs.spec.whatwg.org/#dom-filesystemfilehandle-getfile): a snapshot, which the later writes do not change. The task fails with a NotFoundError when the file does not exist.

public Task<File> GetFile()

Move overloads

Move(FileSystemDirectoryHandle?, string?)

FileSystemFileHandle.cs
  • Experimental (WEBPLATEXP0007)

Moves the file to another directory of the file system, with its name or with newName: see FileSystemFileHandle.Move.

[Experimental("WEBPLATEXP0007", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public Task Move(FileSystemDirectoryHandle? destinationDirectory, string? newName = null)
Parameters
destinationDirectory FileSystemDirectoryHandle?
newName string?
Returns

Task

  • Experimental (WEBPLATEXP0007)

Renames the file (the move() method that the browsers implement for the files of the origin private file system; it is not in the File System Standard yet, see https://github.com/whatwg/fs/pull/10): the handle then locates the file at its new path. A file that has the new name is replaced. The task fails with a TypeErrorException for an invalid name, a NotFoundError when the file does not exist, and a NoModificationAllowedError while the file, or the file it replaces, is locked.

[Experimental("WEBPLATEXP0007", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public Task Move(string newName)
Parameters
newName string
Returns

Task