3

Trying to download an excel file from a .NET Core API.

var filename = doc.Name + Path.GetExtension(filePath);
// filename would be Name øæäåöõ.xlsx
var contentType = doc.ContentType;
return File(stream, contentType, filename, modifiedTime, null);

But the file is downloaded as Name ______.xlsx. The special characters are missing! Tried adding Content-Disposition from this post, but that didn't work either.

What am I missing here?

My response headers from Chrome:

enter image description here

kelsier
  • 4,050
  • 5
  • 34
  • 49
  • 2
    There are two `filename` entries in the `Content-Disposition` header. Could you try to unescape the second with the UTF-8. – burnsi Jun 22 '22 at 14:27
  • 1
    @burnsi OK, got it. I changed my code to `Response.Headers.Add("Content-Disposition", attachment;filename=" + escapedFileName); return File(stream, contentType, modifiedTime, null);` and unescaped in the frontend! Thanks. – kelsier Jun 22 '22 at 16:41

0 Answers0