Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Provide a small working example that shows the issue.
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
using System.Data.Common;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using CsvHelper;
using Dapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
namespace WebApplication1.Services
{
public class CsvService(DbConnection dbConnection) : ControllerBase
{
[HttpGet]
public async Task DownloadCsv(string query, string fileName)
{
var response = Response;
response.ContentType = "text/csv";
response.Headers.Add("Content-Disposition", new ContentDispositionHeaderValue("attachment")
{
FileName = fileName
}.ToString());
var dataRecords = dbConnection.Query(query, buffered: false);
using var writer = new StreamWriter(response.Body);
using var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture);
await csvWriter.WriteRecordsAsync(dataRecords);
}
}
}
Describe the bug A clear and concise description of what the bug is.![image](https://github.com/JoshClose/CsvHelper/assets/31265244/e1c6c90f-d6c8-4569-a515-d9c65ebd22cf)
To Reproduce Provide a small working example that shows the issue.
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.![image](https://github.com/JoshClose/CsvHelper/assets/31265244/1a7af2be-05f0-4882-8355-18d52d83671a)
Additional context