Snail.Toolkit.Blazor.Extensions.File 1.0.0

dotnet add package Snail.Toolkit.Blazor.Extensions.File --version 1.0.0
                    
NuGet\Install-Package Snail.Toolkit.Blazor.Extensions.File -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Snail.Toolkit.Blazor.Extensions.File" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Snail.Toolkit.Blazor.Extensions.File" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Snail.Toolkit.Blazor.Extensions.File" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Snail.Toolkit.Blazor.Extensions.File --version 1.0.0
                    
#r "nuget: Snail.Toolkit.Blazor.Extensions.File, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Snail.Toolkit.Blazor.Extensions.File@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Snail.Toolkit.Blazor.Extensions.File&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Snail.Toolkit.Blazor.Extensions.File&version=1.0.0
                    
Install as a Cake Tool

Toolkit.Blazor.Extensions.File

Extension for the framework Blazor

Installation

dotnet add package Snail.Toolkit.Blazor.Extensions.File

Advanced Usage

<TExportFile Name="name_file" Binary="@Value">
    <p class="_wp">@context</p>
</TExportFile>

@code {
    [Parameter] public Binary? Value { get; set; }
}
<TImportFile OnUpload="@_onBinary" OnProgress="@_onProgress">
    <div class="_aa">
        @if (context)
        {
            <svg class="loader" viewBox="0 0 50 50">
                <circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5"></circle>
            </svg> 
        }
        <p class="_ap">add file</p>
    </div>
</TImportFile>

@code {
    private async Task _onBinary(Binary binary) => await OnBinary.InvokeAsync(binary);

    private async Task _onProgress(int value)
    {
        _progress = value;
        await Task.Delay(1); // Simulate async work (e.g., updating UI)
    }
}

Toolkit.Blazor.Extensions.File

A comprehensive file handling extension for Blazor applications, providing easy-to-use components for file import/export operations.

Installation

dotnet add package Snail.Toolkit.Blazor.Extensions.File

Features

  • File Export: Download files with custom UI templates
  • File Import: Upload files with progress tracking
  • Binary Handling: Streamlined binary data management
  • Customizable UI: Fully templatable components
  • Progress Tracking: Real-time upload progress reporting

Basic Usage

File Export Component

<TExportFile Name="document.pdf" Binary="@pdfData">
    <button class="download-btn">
        Download PDF
    </button>
</TExportFile>

@code {
    private Binary? pdfData = new Binary(File.ReadAllBytes("sample.pdf"), "application/pdf");
}

File Import Component

<TImportFile OnUpload="HandleFileUpload" OnProgress="UpdateProgress">
    <div class="upload-area">
        <span>Drag & drop files here</span>
    </div>
</TImportFile>

@code {
    private async Task HandleFileUpload(Binary file)
    {
        // Process uploaded file
    }
    
    private void UpdateProgress(int progress)
    {
        // Update UI with progress percentage
    }
}

Advanced Usage

Custom Export Template with Context

<TExportFile Name="report.docx" Binary="@reportData">
    <p class="file-info">
        <span>@context</span> 
        <i class="download-icon"></i>
    </p>
</TExportFile>

Import with Progress Indicator

<TImportFile OnUpload="@_onBinary" OnProgress="@_onProgress">
    <div class="upload-container">
        @if (context)  
        {
            <div class="progress-bar">
                <div style="width: @_progress%"></div>
            </div>
            <span>@_progress%</span>
        }
        else
        {
            <span>Select File</span>
        }
    </div>
</TImportFile>

@code {
    private int _progress;
    
    private async Task _onBinary(Binary binary) => await OnBinary.InvokeAsync(binary);

    private async Task _onProgress(int value)
    {
        _progress = value;
        StateHasChanged();
    }
}

Component API Reference

TExportFile

Property Type Description
Name string The filename for the exported file
Binary Binary The binary data to download
ChildContent RenderFragment<string> Template with filename context

TImportFile

Property Type Description
OnUpload EventCallback<Binary> Callback when file upload completes
OnProgress EventCallback<int> Progress percentage callback
ChildContent RenderFragment<bool> Template with upload state context
Multiple bool Allow multiple file uploads (default: false)
Accept string Accepted file types (e.g., ".pdf,.docx")

Best Practices

  1. Large Files: For files > 50MB, consider chunked uploads
  2. Memory: Dispose Binary objects after use

License

Toolkit.Blazor.Extensions.File is a free and open source project, released under the permissible MIT license.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 168 6/1/2025