markthewizard1234
markthewizard1234

Reputation: 443

Chrome appending -- to end of filename

string fileName = "test.txt";
byte[] docBytes = getDocumentBytes();

return File(docBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);

This returns a file called "test.txt" on Firefox and Edge, however on Chrome it returns a file called "test.txt--". Does anyone know why it behaves in this manner? Is there a way to fix this in the code?

Upvotes: 1

Views: 54

Answers (1)

markthewizard1234
markthewizard1234

Reputation: 443

Well this was hard to find out.

Chrome converts whitespace at the end of the filename into '-'.

 return File(docBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName.Trim());

The trim fixes this problem.

Upvotes: 2

Related Questions