From 2c6903827d07ee252131c5993dbe3a1d71c54aa3 Mon Sep 17 00:00:00 2001 From: Dominic NEED Date: Wed, 13 Dec 2023 15:09:19 +0000 Subject: [PATCH 1/2] Return empty spreadsheet when no results --- .../Pages/ProjectList/Index.cshtml.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs index cc20b185f..6fc36a1a2 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs @@ -8,6 +8,7 @@ using Dfe.PrepareConversions.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; @@ -62,7 +63,18 @@ public async Task OnGetDownload() } else { - return null; + var stream = new MemoryStream(); + var writer = new StreamWriter(stream); + writer.Write(""); + writer.Flush(); + stream.Position = 0; + + var fileStreamResult = new FileStreamResult(stream, "text/csv") + { + FileDownloadName = "empty.csv" + }; + + return fileStreamResult; } } From d3d1aa1b1f42586036d98f059fa38b8f6ba44e5b Mon Sep 17 00:00:00 2001 From: Dominic NEED Date: Wed, 13 Dec 2023 15:10:08 +0000 Subject: [PATCH 2/2] File name and stream is empty when no matching filters --- .../Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs index 6fc36a1a2..549620cae 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs @@ -77,5 +77,4 @@ public async Task OnGetDownload() return fileStreamResult; } } - }