#region 文件下载 /// <summary> /// 文件直接下载 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="filename">文件名称</param> public static void FileDownload(string filePath, string filename) { FileStream fileStream = new FileStream(HttpContext.Current.Server.MapPath(filePath), FileMode.Open); long fileSize = fileStream.Length; HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=/"" + filename + "/";"); HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString()); byte[] fileBuffer = new byte[fileSize]; fileStream.Read(fileBuffer, 0, (int)fileSize); HttpContext.Current.Response.BinaryWrite(fileBuffer); HttpContext.Current.Response.End(); } #endregion