//下载文件 public ActionResult DownFile(String filename) { FileService fservice = new FileService(); if (!fservice.CheckFileExsit(filename)) { ViewData["DownloadState"] = "文件不存在"; } else { fservice.UpdateDownLoadTime(filename); ViewData["DownloadState"] = "开始下载"; FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "data/" + filename, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(filename)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } return(View("DownFile")); }