/// <summary> /// /// </summary> /// <param name="id"></param> public void DownLoad(string id) { string[] arrStr = id.Split('/'); string informNo = arrStr[0]; DataTable dtInfo = UserAptitudeMan.getNewFile(informNo); if (dtInfo.Rows[0][0].ToString() != "") { byte[] bContent = (byte[])dtInfo.Rows[0]["FileInfo"]; Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(dtInfo.Rows[0]["FileName"].ToString())); //Response.BinaryWrite(bContent); //Response.Flush(); //Response.End(); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", bContent.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/msword"; // 把文件流发送到客户端 Response.BinaryWrite((byte[])dtInfo.Rows[0]["FileInfo"]); System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); } }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult GetFile() { var id = Request["data1"]; DataTable dt = UserAptitudeMan.getNewFile(id); string ID = ""; string name = ""; string file = ""; if (dt.Rows.Count > 0) { ID = dt.Rows[0]["ID"].ToString(); name = dt.Rows[0]["FileName"].ToString(); file = dt.Rows[0]["FileInfo"].ToString(); } return(Json(new { success = "true", id = ID, Name = name, File = file })); }