Giter Club home page Giter Club logo

blazorfilesaver's Introduction

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

blazorfilesaver's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

blazorfilesaver's Issues

Compile Errors Preview 9

I'm getting the following errors on "CreateHostBuilder(args).Build().Run();" when I try to compile a Blazor server-side app.

System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BlazorFileSaver.IBlazorFileSaver Lifetime: Singleton ImplementationType: BlazorFileSaver.BlazorFileSaverJS': Cannot consume scoped service 'Microsoft.JSInterop.IJSRuntime' from singleton 'BlazorFileSaver.IBlazorFileSaver'.)'

InvalidOperationException: Cannot consume scoped service 'Microsoft.JSInterop.IJSRuntime' from singleton 'BlazorFileSaver.IBlazorFileSaver'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.