日期:2014-05-17 浏览次数:20443 次
public ActionResult GetFile(string id)
{
//var dl = DownloadsDal.GetById(id);
var book = LibraryBLL.GetBook(id);
if (!(bool)book.CanDownload)
return Content(ClientScript.AlertAndBack("亲,这样做,不对哦!!!")); //防止用户输入超链接下载
if (book == null)
return JavaScript(ClientScript.AlertAndBack("对不起,不存在指定的下载项目"));
StringBuilder sb = new StringBuilder("~" + book.VirDir).Replace("\\","/").Append(Constants.BookName).Append(book.Extension);
string filePath = HttpContext.Server.MapPath(sb.ToString());
if (!System.IO.File.Exists(filePath))
return Content(ClientScript.AlertAndBack("对不起,要下载的文件不存在,该文件可能已被删除或改名"));
FilePathResult fpr = File(filePath, "application/octet-stream", book.Title);
LibraryBLL.UpdateDownloadTimes(id); //更新下载次数
return fpr;
}