Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Last active June 9, 2017 03:48
Show Gist options
  • Save johnmmoss/8ee16837513ab69de4f3 to your computer and use it in GitHub Desktop.
Save johnmmoss/8ee16837513ab69de4f3 to your computer and use it in GitHub Desktop.
ASP.NET MVC FileStreamResult Example
// /File/Stream
public FileStreamResult Stream()
{
var fileContent = new byte[] { Ascii.one, Ascii.Comma, Ascii.two, Ascii.Comma, Ascii.three };
var stream = new MemoryStream(fileContent);
var fileStreamResult = new FileStreamResult(stream, mimeType);
fileStreamResult.FileDownloadName = "FileStreamExample.csv";
return fileStreamResult;
}
// File/Stream2
public FileStreamResult Stream2()
{
byte[] fileContent = new[] { Ascii.one, Ascii.Comma, Ascii.two, Ascii.Comma, Ascii.three };
return File(new MemoryStream(fileContent), mimeType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment