public ActionResult DownFile(string filePath, string fileName) { string FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc"; string Questiong_Name = @"" + DateTime.Now.ToString("yyyyMMddhhmmss") + @"-xqx\"; string temppath = Server.MapPath(@"~\Generate\question.doc"); string savepath = Server.MapPath(@"~\Generate\"); string BasePath = Server.MapPath(@"~"); savepath = savepath + Questiong_Name; if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } savepath = savepath + FileName; Question_Export qe = new Question_Export(null); //qe.Generate(BasePath, temppath, savepath,2); FileStream fs = new FileStream(savepath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(FileName)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); if (System.IO.File.Exists(savepath))//判断文件是否存在 { System.IO.File.Delete(savepath);//执行IO文件删除 } return new EmptyResult(); }
public FileStreamResult DownFile1(string filePath, string fileName) { string absoluFilePath = Server.MapPath(@"~\UploadFiles\g1.gif"); string temppath = Server.MapPath(@"~\Generate\question.doc"); string savepath = Server.MapPath(@"~\Generate\"); string FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc"; savepath = savepath + FileName; //return File(new FileStream(absoluFilePath, FileMode.Open), "application/octet-stream", Server.UrlEncode("sss.gif")); Question_Export qe = new Question_Export(null); //qe.Generate("",temppath, savepath,0); return null; }