Files
lux/Lux.UI/Components/Pages/Download.cshtml.cs
T
Samuele Locatelli 034e263c92 Aggiunta pagina download jwd
aggiunta parziale test ricalcolo balance
2026-01-13 11:06:07 +01:00

49 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.IO;
namespace Lux.UI.Components.Pages
{
/// <summary>
/// Gestione download file csv
///
/// da valutare eventualmente xlsx con https://github.com/closedxml/closedxml
/// </summary>
public class DownloadModel : PageModel
{
#region Public Constructors
public DownloadModel(IWebHostEnvironment env)
{
_env = env;
}
#endregion Public Constructors
#region Public Methods
public IActionResult OnGet()
{
string fileName = "file.txt";
if (Request.Query.ContainsKey("fileName"))
{
fileName = Request.Query["fileName"];
}
var filePath = Path.Combine(_env.ContentRootPath, "temp\\", fileName);
//var filePath = Path.Combine(_env.WebRootPath, "..\\temp\\", fileName);
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
return File(fileBytes, "application/force-download", fileName);
}
#endregion Public Methods
#region Private Fields
private readonly IWebHostEnvironment _env;
#endregion Private Fields
}
}