1

I'm working on ASP.NET MVC and I want to force the download of plain text file instead of viewing it.

I was initially using this:

return File(download, "application/txt", "Result.txt");

And my colleague is telling me I should do this:

return File(download, System.Net.Mime.MediaTypeNames.Application.Octet, "Result.txt");

We got into some debate over advantages of each, but I still want to know which is the proper one. My computer issues download on both MIMEs on current Firefox & IE versions. IE doesn't show any difference, but Firefox has. File type when downloading application/txt is TXT, but when downloading ...Application.Octet file type is "Secure download manager" (what what?..)

Carl di Ortus
  • 157
  • 4
  • 13

1 Answers1

2

When you have a custom controller that explicitely send the file (i.e. by sending Content-Disposition/Content-Type HTTP Headers, etc..), then you should give the right MIME type (text/plain here).

IMO, the MIME type application/octet-stream is used when you don't want to search for the right MIME type (or it won't be recognize anyway), but still want to fire a download.

As shree.pat18 said, text/plain can be wrote System.Net.Mime.MediaTypeNames.Text.Plain in C#.

Edit: If you google the question, you may have more solutions: What content type to force download of text response?

Community
  • 1
  • 1
Oliboy50
  • 2,661
  • 3
  • 27
  • 36
  • `System.Net.Mime.MediaTypeNames.Text.Plain` issues the download but I sense something not right when the browser is identifying the file type. If I provide `text/plain` then it will not fire up a download but render the text – Carl di Ortus Jul 11 '14 at 08:18
  • Octet is good for anything, but if I know it's txt and I want to fire a download, should I really use it? How come `application/txt` is not good? Am I being stubborn here or do I really miss something that does not have clear specification? – Carl di Ortus Jul 11 '14 at 08:53