Java教程

blazor 下载txt 下载文件

本文主要是介绍blazor 下载txt 下载文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.nuget安装BlazorDownloadFile

2.使用

 

@page "/"
@inject HttpClient http
@inject IBlazorDownloadFileService BlazorDownloadFileService

<h1>Hello, world!</h1>

<button @onclick="@down1">下载</button>
<button @onclick="@do1">测试</button>

@code{
    public async void down1()
    {
        using var response = await http.GetAsync("22.txt");
        using var stream = await response.Content.ReadAsStreamAsync();

        await BlazorDownloadFileService.DownloadFile("33.txt", stream, "application/octet-stream");
    }

    public async void do1()
    {
        using var response = await http.GetAsync("22.txt");

        //读取txt
        using var stream = await response.Content.ReadAsStreamAsync();
        StreamReader sr = new StreamReader(stream);
        var str = sr.ReadToEnd();


        Console.WriteLine(str);
    }
}

 

 

 

 

 

 

 

 

 

这篇关于blazor 下载txt 下载文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!