var filePath=@"d:\超1G文件.zip";
FileInfo downloadFile = new FileInfo(filePath);//支持1G超大文件
//等几分钟后删除
Task task1 = new Task(() =>
{
Thread.Sleep(1000 * 60 * 10);
File.Delete(filePath);
});
task1.Start();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.ContentType = "application/octet-stream";
var fName = HttpUtility.UrlEncode(Path.GetFileName(filePath)).Replace('+', ' ');//文件名编码
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fName);
HttpContext.Current.Response.AppendHeader("Content-Length", downloadFile.Length.ToString());
HttpContext.Current.Response.WriteFile(downloadFile.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
标签:删除,filePath,超大,downloadFile,Current,1G,HttpContext,Response
From: https://www.cnblogs.com/anjun-xy/p/18574256