public static void ToDownload(string serverfilpath, string filename)
{
FileStream fileStream = new FileStream(serverfilpath, FileMode.Open);
long fileSize = fileStream.Length;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" +UTF_FileName(filename));
////attachment --- 作为附件下载
////inline --- 在线打开
HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
HttpContext.Current.Response.BinaryWrite(fileBuffer);
fileStream.Close();
HttpContext.Current.Response.End();
}
private static string UTF_FileName(string filename)
{
return (HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)).Replace("+", "%20");
}
serverfilpath 是文件路径 filename是需要的文件名
文件下载之前用DSOFile修改了摘要,在公司的服务器上是正常的,在自己机器上却是摘要被修改,下载下来的文件竟然没有摘要了?,环境一样,公司的系统补丁少打了点。。
可能是什么原因呢