public static void DownLoad(string FullFileName)
{
var DownloadFile = new FileInfo(HostingEnvironment.ApplicationPhysicalPath + FullFileName);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FullFileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
本文介绍了一种在ASP.NET中实现文件下载的方法。通过提供的代码示例,展示了如何使用HttpContext对象来设置响应头并发送文件到客户端。此方法适用于需要在Web应用中提供文件下载功能的场景。
1689

被折叠的 条评论
为什么被折叠?



