views:

532

answers:

1

ASP.NET has four different types of file results:

  • FileContentResult: Sends the contents of a binary file to the response.
  • FilePathResult: Sends the contents of a file to the response
  • FileResult: Returns binary output to write to the response
  • FileStreamResult: Sends binary content to the response by using a Stream instance

Those descriptions are take from MSDN and with the exception of the FileStreamResult the first three sound identical. So what is the difference between them?

+11  A: 

FileResult is an abstract base class for all the others.

FileContentResult - you use it when you have a byte array you would like to return as a file FilePathResult - when you have a file on disk and would like to return it's content (you give a path) FileStreamResult - you have a stream open, you want to return it's content as a file

However, you'll rarely have to use this classes - you just use one of Controller.File overloads and let asp.net mvc do the magic for you

maciejkow