Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

IvanJosipovic/BlazorFileSaver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlazorFileSaver

Demo Nuget (with prereleases) Nuget (with prereleases)

Blazor Component wrapper for FileSaver.js

Demo

Sample

Installation

  • Add Nuget BlazorFileSaver
  • Add <script src="_content/BlazorFileSaver/BlazorFileSaver.min.js"></script> to the index.html or _Hosts.cshtml
  • Add AddBlazorFileSaver() to the ConfigureServices in Program.cs as noted below

Program.cs

namespace BlazorFileSaver.Sample
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            
            builder.RootComponents.Add<App>("app");

            builder.Services.AddBlazorFileSaver(); // Add This!

            await builder.Build().RunAsync();
        }
    }
}

Example

@page "/sample"

<h1>BlazorFileSaver.Sample</h1>

<input type="text" @bind="FileName" />

<buton @onclick="Save" class="btn btn-primary">Save</buton>

<textarea class="form-control" type="text" @bind="Data" rows="20"></textarea>

@code {
    [Inject]
    private IBlazorFileSaver BlazorFileSaver { get; set; }
    
    private string FileName { get; set; } = "Sample.txt";

    private string Data { get; set; } = "Sample Text";

    private async Task Save()
    {
        await BlazorFileSaver.SaveAs(FileName, Data);
    }
}

More Examples

SaveAsBase64 Zip