【C#】【HttpClient】下载网络文件
WebClient 参考:https://blog.csdn.net/qq_34739157/article/details/125373179
HttpClient 参考(WebClient已经过时了):https://blog.csdn.net/qq_33033813/article/details/104919431?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-104919431-blog-124631842.235^v29^pc_relevant_default_base3&spm=1001.2101.3001.4242.1&utm_relevant_index=3
以上方法只能下载到服务器上,不能下载到本地
Blazor-JS调用方法下载到本地下载文件夹
1、razor页面:@inject IJSRuntime JS
-------------------------------------code start------------------------------------
byte[] fileBytes = File.ReadAllBytes(tempfilename);
var fileStream = new MemoryStream(fileBytes);
using var streamRef = new DotNetStreamReference(stream: fileStream);
await JS.InvokeVoidAsync("downloadFileFromStream", downFileName, streamRef);
-------------------------------------code end------------------------------------
tempfilename:需要下载的文件地址,例如:“C:\123\download\销售合同模版.xlsx”
downFileName:文件名,例如:“销售合同.xlsx”
streamRef:DotNetStreamReference 数据流