Initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace SharepointToolbox.Web.Services.Export;
|
||||
|
||||
/// <summary>
|
||||
/// Triggers browser file downloads from Blazor Server components.
|
||||
/// Converts string export outputs to bytes and invokes JS download.
|
||||
/// </summary>
|
||||
public class WebExportService
|
||||
{
|
||||
private readonly IJSRuntime _js;
|
||||
|
||||
public WebExportService(IJSRuntime js) { _js = js; }
|
||||
|
||||
public async Task DownloadCsvAsync(string content, string fileName)
|
||||
{
|
||||
var bytes = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true).GetBytes(content);
|
||||
await _js.InvokeVoidAsync("sptb.downloadFile", fileName, "text/csv;charset=utf-8", Convert.ToBase64String(bytes));
|
||||
}
|
||||
|
||||
public async Task DownloadHtmlAsync(string content, string fileName)
|
||||
{
|
||||
var bytes = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false).GetBytes(content);
|
||||
await _js.InvokeVoidAsync("sptb.downloadFile", fileName, "text/html;charset=utf-8", Convert.ToBase64String(bytes));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user