您的位置:首页 > 其它

从服务器下载文件的方法

2008-11-28 17:08 106 查看
public static void DownloadFile(string physicalFilePath){    FileStream stream=null;    stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);       int bufSize = (int)stream.Length;    byte[] buf = new byte[bufSize];    int bytesRead = stream.Read(buf, 0, bufSize);    HttpContext.Current.Response.ContentType = "application/octet-stream";    HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));    HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);    HttpContext.Current.Response.End();}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: