Created
May 10, 2012 23:22
-
-
Save roalcantara/2656527 to your computer and use it in GitHub Desktop.
ASP.NET > Generate a TXT file in memory and download it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte[] buffer; | |
using (var memoryStream = new System.IO.MemoryStream()) | |
{ | |
buffer = Encoding.Default.GetBytes("Sample text); | |
memoryStream.Write(buffer, 0, buffer.Length); | |
Response.Clear(); | |
Response.AddHeader("Content-Disposition", "attachment; filename=filename.txt"); | |
Response.AddHeader("Content-Length", memoryStream.Length.ToString()); | |
Response.ContentType = "text/plain"; //This is MIME type | |
memoryStream.WriteTo(Response.OutputStream); | |
} | |
Response.End(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment