62,072
社区成员
发帖
与我相关
我的任务
分享
string fileName = System.IO.Path.GetFileName(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open);
KyLaw.BLL.KY_USER user = new KyLaw.BLL.KY_USER();
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
HTTP/1.1 200 OK
Date: Fri, 14 Oct 2011 11:41:31 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment; filename=bb2011.rar
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: application/octet-stream