110,533
社区成员
发帖
与我相关
我的任务
分享
public ActionResult MyFile(string key)
{
if (!string.IsNullOrWhiteSpace(key))
{
var query = _industryRespository.FindIndustryStudyListByKeys(key);
var result = query;
ViewBag.Key = query.Keys;
var dl = query.Download;
ViewBag.Result = result;
if (dl==null)
{
Response.Write("<script>alert('文件已过期');</script>");
}
else
{
TestFile(dl);
}
}
return View("AllReport");
}
public void TestFile(string fileName)
{
//fileName = "0112.doc";//客户端保存的文件名
var filePath = Server.MapPath("~/IndustryStudyFile/");//路径
FileInfo fileInfo = new FileInfo(filePath + fileName);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
}
if ((dl==null)||(dl==""))
{
Response.Write("<script>alert('文件已过期');</script>");
}