private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
文件下载方法
最新推荐文章于 2024-08-26 14:54:22 发布
本文介绍了一种使用ASP.NET进行文件下载的方法。通过设置HTTP响应头来触发浏览器的下载行为,实现了将服务器上的文件直接提供给用户下载的功能。具体步骤包括清除当前响应内容、设置Content-Type为application/octet-stream,并附加文件名及大小等信息。
445

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



