C# Asp.net write file to client

You could use the Response.ContentType like this

Response.ContentType = "text/plain";
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.AddHeader("Content-Disposition", "attachment;filename=yourfile.txt");

This of course works if you want to write a text file. In case you want to write a .doc for example you change the ContentType to “application/msword” etc…

Leave a Comment