asp.net 文件下载。
asp.net 文件流 文件下载
#region 文件下载 public void downloadfile(int id) { try { chr_Action_Apply apply = db.chr_Action_Apply.Find(id); string s_fileName = Request["FileName"];//文件名 Response.ContentType = "application/ms-download"; string s_path = HttpContext.Server.MapPath("/UpLoad/Other/") + s_fileName;//保存路径 System.IO.FileInfo file = new System.IO.FileInfo(s_path); Response.Clear(); Response.AddHeader("Content-Type", "application/octet-stream"); Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", file.Length.ToString()); Response.WriteFile(file.FullName); Response.Flush(); Response.Clear(); Response.End(); apply.clicknum = apply.clicknum + 1;//下载次数+1 db.SaveChanges(); } catch (Exception) { Response.Write("<script>alert('文件下载失败,请重试...');history.go(-1);</script>"); } } #endregion