Code-Quickie: How to do a file download from ASP.Net
So you want to let the user save a file that you generate from an ASP.Net page or httphandler?
It’s simple once you know how to set up your response headers:
Response.ContentType = sMimeType;
Response.ContentEncoding = System.Text.Encoding.GetEncoding(sEncoding);
“attachment; filename=””+sReportFileName+”.” + sExtension + “””);
Response.CacheControl = “private”;
The most tricky parts to figure out were the Content-Disposition and CacheControl headers. The latter, I only discovered some comparison using Fiddler, which by the way is an indispensable tool for any serious web developer.