Basically you set the response object to oclet type, push in the data and send it off. The client browser determines how it will display any needed dialogs to the user.
This is from a download utility page on an internal web app. The full code includes protection against the user trying to read files outside of its path sandbox that I ommited for this example.
string document = "... some server document file name ...";
string fullpath = Server.MapPath("your path"+document);
Response.ContentType = ExtentionToContentType(document);
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", document));
byte[] data = System.IO.File.ReadAllBytes(fullpath);
Response.AppendHeader("Content-Length", data.Length.ToString());
Response.BinaryWrite(data);
Response.End();
public string ExtentionToContentType(string file)
{
switch (System.IO.Path.GetExtension(file).ToLower())
{
case ".xls": return "application/vnd.ms-excel";
case ".doc": case ".docx": return "application/msword";
case ".ppt": return "application/vnd.ms-powerpoint";
case ".mdb": return "application/x-msaccess";
case ".zip": return "application/zip";
case ".jpg": case ".jpeg": case ".jpe": return "image/jpeg";
case ".tiff": return "image/tiff";
case ".bmp": return "image/bmp";
case ".png": return "image/png";
case ".gif": return "image/gif";
case ".avi": return "video/x-msvideo";
case ".mpeg": return "video/mpeg";
case ".rtf": case ".rtx": return "text/richtext";
case ".txt": return "text/plain";
case ".pdf": return "application/pdf";
default: return "application/x-binary";
}
}