FileInput

BitFileInput component wraps the HTML file input element and allows the user to select file(s) without uploading them. The selected files are returned to the C# context for further processing. It provides several options including single or multiple file selection, drag and drop support, file size validation, and file extension filtering.

Usage

Basic
Select file(s) to see them in the component.

Multiple
Multiple files can be selected.

AutoReset
Automatically resets the BitFileInput state each time before browsing files.

Append
When selected, additional files will be appended to the existing list without overwriting previous selections.

MaxSize
The file size can be limited using the MaxSize parameter (1 MB in this example).

AllowedExtensions
Limits file browsing by the provided file extensions.

Removable
Enables the remove functionality of the BitFileInput.

Events
Use OnChange to handle file selection and ReadContentAsync to access the file's byte array content.



Selected files:

Templates
The BitFileInput can be further customized using templates.

Drag and drop or
Browse files
Public API
Use custom methods to interact with the file input.


API

BitFileInput parameters
Name
Type
Default value
Description
Accept string? null Accepted file types for the file browser using MIME types or file extensions (e.g., "image/*", ".pdf,.doc"). Applied to the underlying HTML input element's accept attribute.
AllowedExtensions IReadOnlyCollection<string> ["*"] Allowed file extensions for validation purposes (e.g., [".jpg", ".png", ".pdf"]). Use ["*"] to allow all file types. Files not matching these extensions will be marked as invalid.
Append bool false Whether to append newly selected files to the existing file list instead of replacing it.
AutoReset bool false Whether the file input is automatically reset (cleared) before opening the file browser dialog, allowing the same file to be selected multiple times consecutively.
HideFileList bool false Whether to hide the file list that displays the selected files in the UI.
HideLabel bool false Whether to hide the default browse button label from the UI.
Label string Browse The text displayed on the browse button. Defaults to "Browse".
LabelTemplate RenderFragment? null Custom Razor template for the browse button area, allowing full customization of the file selection trigger UI.
MaxSize long 0 Maximum allowed file size in bytes for validation. Files exceeding this size will be marked as invalid. Set to 0 for no size limit.
MaxSizeErrorMessage string? null Custom error message displayed when a file exceeds the maximum size limit. Defaults to "The file size is larger than the max size".
Multiple bool false Whether to allow selecting multiple files simultaneously through the file browser dialog.
NotAllowedExtensionErrorMessage string File type not allowed Custom error message displayed when a file's extension is not in the allowed extensions list. Defaults to "The file type is not allowed".
OnChange EventCallback<BitFileInputInfo[]> Callback invoked when the file selection changes, providing an array of BitFileInputInfo representing all selected files.
ShowRemoveButton bool false Whether to display a remove button next to each file in the file list, allowing individual file removal.
FileViewTemplate RenderFragment<BitFileInputInfo>? null Custom Razor template for rendering individual file items in the file list. Receives a BitFileInputInfo context for each file.
BitFileInput public members
Name
Type
Default value
Description
Files BitFileInputInfo[]? null A read-only list of all currently selected files with their metadata, validation status, and content.
InputId string? The unique identifier of the underlying HTML file input element.
RemoveFile (BitFileInputInfo? fileInfo = null) => void Removes a specific file from the selected files list, or clears all files when no file is specified.
Browse Task Opens the file browser dialog programmatically, allowing users to select files. If AutoReset is enabled, the input is reset before opening.
ReadContentAsync (BitFileInputInfo fileInfo) => Task Reads the content of the specified file from the browser and populates its Content property with the byte array. Only reads valid and enabled files.
Reset Task Clears all selected files and resets the file input to its initial state.
BitComponentBase parameters
Name
Type
Default value
Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters.
Id string? null Gets or sets the unique identifier for the component's root element.
IsEnabled bool true Gets or sets a value indicating whether the component is enabled and can respond to user interaction.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.
BitComponentBase public members
Name
Type
Default value
Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.
BitFileInputInfo properties
Represents metadata, validation state, and content of a file selected through BitFileInput.
Name
Type
Default value
Description
ContentType String string.Empty The MIME content type of the file (e.g., "image/png", "application/pdf").
Name String string.Empty The name of the file including its extension (e.g., "document.pdf").
Size long The size of the file in bytes.
FileId String string.Empty A unique identifier (GUID) assigned to the file upon selection, used to reference the file in JavaScript interop.
Index int The zero-based index of the file in the current selection list.
IsValid bool true Whether the file has passed all validation checks including size constraints and allowed extensions.
Message string? null The validation error message when the file has failed a validation check (e.g., size or extension). This is null when the file is valid.
Content byte[]? null The file content as a byte array, populated by calling ReadContentAsync. This is null by default and only loaded on demand.
BitVisibility enum
Name
Value
Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).
BitDir enum
Name
Value
Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

You can give us your feedback through our GitHub repo by filing a new Issue or starting a new Discussion.

Or you can review / edit this page on GitHub.

Or you can review / edit this component on GitHub.
  • On this page