try { FullFileName = Server.MapPath(FileName); //FileName--要下载的文件名 FileInfo DownloadFile= new FileInfo(FullFileName); if(DownloadFile.Exists) { 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.ASCII)); Response.AppendHeader("Content-Length",DownloadFile.Length.ToString()); Response.WriteFile(DownloadFile.FullName); Response.Flush(); Response.End(); } else { //文件不存在 } } catch { //文件不存在 }
本文转自 BruceAndLee 51CTO博客,原文链接:http://blog.51cto.com/leelei/188984,如需转载请自行联系原作者