I have to return a csv file template which has some columns with german characters in my one of my api enpoint.
This is the simplified version of endpoint:
[HttpGet]
[ProducesResponseType(typeof(Stream), StatusCodes.Status200OK)]
[Route("template")]
public async Task GetTemplate()
{
Response.StatusCode = StatusCodes.Status200OK;
Response.ContentType = "text/csv";
Response.Headers.AddContentDispositionAttachment("Template.csv");
CsvConfiguration csvConfiguration = new (new CultureInfo("de-de"))
{
Delimiter = ";",
HasHeaderRecord = false
};
string header = $"Url;Beschreibung;Code;ID;Löschen;Straße;Pünklitch";
using var streamWriter = new StreamWriter(Response.Body, Encoding.UTF8, 65536);
await using var csvWriter = new CsvWriter(streamWriter, csvConfiguration);
await streamWriter.WriteAsync(header);
}
It is pretty straight forward.
The problem is; when I call endpoint via swagger in local or on server and download the file it doesn't show german characters properly. Also when I entagrate endpoint to my Front end and download file via ui it also behave as same way and doesn't show german characters. But when I call the endpoint from browser directly everything looks ok.
This is how csv file looks after download:
Any idea ? How can I fix encoding problem?
I am using .net framwork 6