string path = Server.MapPath(Url.Content("~/") + "UploadFiles/Template/");
FileStream fs = new FileStream(path + file, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
if (Request.UserAgent.ToLower().IndexOf("firefox") > -1) //火狐浏览器
{
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + file + "\"");
}
else //其他浏览器
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file, System.Text.Encoding.UTF8));
}
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();