How To Raise a “File Download” Dialog Box for a Known MIME Type

We’ve got a project where we need to send a text file export to the user. Since it’s all stored in the database, the simplest way is just to dump the data from the page. Unfortunately, if it’s a knowe MIME type, like a text file or pdf, teh browser opens it internally. This means the user will close it when done and get confused because they lost their browser. I usually just launch the script in a pop-up to take care of this, but pop-up blockers are making that much harder.

After about 3 seconds of googling, I came across this oddly helpful page from MS.

So, to implement it in an ASP.NET page, you just need to to the following (courtesy of Greg Hill):
Response.AddHeader("Content-Type", "text/dat");
Response.AddHeader("Content-disposition", "attachment; filename=Export.dat");
Response.Write(data)