FileReader Class

Reads the content of a Blob asynchronously (https://w3c.github.io/FileAPI/#APIASynch). The events (loadstart, progress, load or error, loadend, abort) are fired by the tasks of the event loop of the relevant global object of the reader (the window of the current global object when it is created); a reader created without current global object (e.g. from .NET without script engine) reads the blob and fires the events synchronously.

public sealed class FileReader : EventTarget
Inheritance
EventTarget FileReader

Constructors

NameDescription
FileReader()Creates a reader in the FileReader.Empty state.

FileReader()

FileReader.cs

Creates a reader in the FileReader.Empty state.

public FileReader()

Properties

NameDescription
ErrorGets the error of the read, or null.
OnAbortGets or sets the event handler of the abort event.
OnErrorGets or sets the event handler of the error event.
OnLoadGets or sets the event handler of the load event.
OnLoadEndGets or sets the event handler of the loadend event.
OnLoadStartGets or sets the event handler of the loadstart event.
OnProgressGets or sets the event handler of the progress event.
ReadyStateGets the state of the reader: FileReader.Empty, FileReader.Loading or FileReader.Done.
ResultGets the result of the read: a String, a Byte array (an ArrayBuffer in JavaScript), or null.

Gets the error of the read, or null.

public DomException? Error { get; }

Gets or sets the event handler of the abort event.

public Action<Event>? OnAbort { get; set; }

Gets or sets the event handler of the error event.

public Action<Event>? OnError { get; set; }

Gets or sets the event handler of the load event.

public Action<Event>? OnLoad { get; set; }

OnLoadEnd

FileReader.cs

Gets or sets the event handler of the loadend event.

public Action<Event>? OnLoadEnd { get; set; }

OnLoadStart

FileReader.cs

Gets or sets the event handler of the loadstart event.

public Action<Event>? OnLoadStart { get; set; }

OnProgress

FileReader.cs

Gets or sets the event handler of the progress event.

public Action<Event>? OnProgress { get; set; }

ReadyState

FileReader.cs

Gets the state of the reader: FileReader.Empty, FileReader.Loading or FileReader.Done.

public ushort ReadyState { get; }

Gets the result of the read: a String, a Byte array (an ArrayBuffer in JavaScript), or null.

public FileReaderResult? Result { get; }

Methods

NameDescription
Abort()Aborts the read (https://w3c.github.io/FileAPI/#dfn-abort).
ReadAsArrayBuffer(Blob)Reads the blob as bytes (https://w3c.github.io/FileAPI/#dfn-readAsArrayBuffer).
ReadAsBinaryString(Blob)Reads the blob as a binary string: each byte is a code unit (https://w3c.github.io/FileAPI/#readAsBinaryString).
ReadAsDataUrl(Blob)Reads the blob as a data: URL whose body is base64-encoded (https://w3c.github.io/FileAPI/#dfn-readAsDataURL).
ReadAsText(Blob, string?)Reads the blob as text (https://w3c.github.io/FileAPI/#readAsDataText), decoded with the byte order mark, else the encoding label, else the charset of the type of the blob, else UTF-8.

Aborts the read (https://w3c.github.io/FileAPI/#dfn-abort).

public void Abort()

ReadAsArrayBuffer(Blob)

FileReader.cs

Reads the blob as bytes (https://w3c.github.io/FileAPI/#dfn-readAsArrayBuffer).

public void ReadAsArrayBuffer(Blob blob)

ReadAsBinaryString(Blob)

FileReader.cs

Reads the blob as a binary string: each byte is a code unit (https://w3c.github.io/FileAPI/#readAsBinaryString).

public void ReadAsBinaryString(Blob blob)

ReadAsDataUrl(Blob)

FileReader.cs

Reads the blob as a data: URL whose body is base64-encoded (https://w3c.github.io/FileAPI/#dfn-readAsDataURL).

public void ReadAsDataUrl(Blob blob)

ReadAsText(Blob, string?)

FileReader.cs

Reads the blob as text (https://w3c.github.io/FileAPI/#readAsDataText), decoded with the byte order mark, else the encoding label, else the charset of the type of the blob, else UTF-8.

public void ReadAsText(Blob blob, string? encoding = null)

Constants

NameDescription
DoneThe state of a reader whose read has completed (DONE).
EmptyThe state of a reader that has no read in progress and no result (EMPTY).
LoadingThe state of a reader that is reading a blob (LOADING).

Done

The state of a reader whose read has completed (DONE).

public const ushort Done = 2

Empty

The state of a reader that has no read in progress and no result (EMPTY).

public const ushort Empty = 0

Loading

The state of a reader that is reading a blob (LOADING).

public const ushort Loading = 1